An ftp script for searching and uploading updated files
Source: Internet
Author: User
An ftp script for searching and uploading updated files #! /Bin/ksh #################################### ##################### Date: 2012-12-19 # name: swiftftp. sh # decription: Infinite Loop, which is executed once every 1 minute. search for the changes in the current directory... an ftp script for searching and uploading updated files #! /Bin/ksh #################################### ##################### Date: 2012-12-19 # name: swiftftp. sh # decription: an infinite loop, which is executed once every minute. search for files in the current directory that have been modified for more than 1 minute but not later than #2 minutes, ftp to the front #################################### ################### www.2cto.com datestr = 'date "+ % Y % m % d" '_ logname = dynamicftp $ {datestr }. logchmod + x * if [[! -F $ {_ logname}]; then touch $ {_ logname}; fi # Timestamp of parameter 1 for this function printing # perl usage: perl-e "$ a = 1 + 4; exit ($ a);" cal_timestamp () {perl-e 'use Time: Local; # get current time # parameter, the timestamp yyyymmddhhmm earlier than minu_num must be returned. ss $ minu_num = "$ ARGV [0]"; localtime (time); $ time1 = time-60 * $ minu_num; ($ sec, $ min, $ hr, $ mday, $ mon, $ yr, $ wday, $ yday, $ isdst) = localtime ($ time1); $ yr = $ yr + 1900; $ mon = $ mon + 1; $ beforetime = sprintf ("% d % 0 2d % 02d % 02d % 02d. % 02d ", $ yr, $ mon, $ mday, $ hr, $ min, $ sec ); print "$ beforetime" '"$1" # pass the first parameter of the function to perl} www.2cto.com # The outermost loop while [[1-eq 1]; do # example use of cal_timestamp: oneminubef =$ (cal_timestamp "1") echo "1 minutes before: $ oneminubef ">$ {_ logname} twominubef =$ (cal_timestamp" 2 ") echo" 2 minutes before: $ twominubef ">> {_ logname} # create two older files touch-t $ oneminubef oneminu Bef. tmp touch-t $ twominubef. tmp # find the file list which is younger than 2 minutes but older than 1 minutes # find usage: find-newer file1! File2 touch tempfile01 chmod 777 tempfile01 find.-newer twominubef. tmp! -Newer oneminubef. tmp | grep-v '^. /oneminubef. tmp '| grep-v "^. /$ {_ logname} "| grep-v" {$0} "> tempfile01 # read the file and strcat the files a = 0 filenames = while read line do line = 'echo $ line | sed-e's/^ * // '-e's/* $ // ''# Remove space length = 'echo $ {line} | awk '{ print length ($1 );} ''# calculates the number of characters if [[$ {length}-gt 0]; then # prevents empty lines from being added to newline =$ {line. /filenames = $ filenames "" $ newline a = 'expr $ + 1 'Fi done <tempfile01 rm-rf tempfile01 oneminubef. tmp twominubef. tmp echo "files: $ filenames" >$ {_ logname} _ username = test _ passwd = test if [[$ a-gt 0]; then ftp-in 192.168.93.77 <! User $ {_ username }$ {_ passwd} bi mput $ filenames bye! Fi if [[$? -Eq 0 & a-gt 0]; then echo 'date' "successfully put $ a files on server" >$ {_ logname} elif [[a-gt 0]; then echo 'date' "put files error! ">>$ {_ Logname} else echo 'date'" no files need to be put! ">>$ {_ Logname} fi sleep 60 done
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.