linux查找今天上传的文件,一个查找并上传已更新文件的ftp脚本

一个查找并上传已更新文件的ftp脚本

一个查找并上传已更新文件的ftp脚本

#!/bin/ksh

########################################################

#Date: 2012-12-19

#name: swiftftp.sh

#decription: 无限循环,每1分钟执行一次,查找当前目录中

修改时间超过1分钟但未超过

# 2分钟的文件,ftp到前置上

########################################################

www.2cto.com

datestr=`date "+%Y%m%d"`

_logname=dynamicftp${datestr}.log

chmod +x *

if [[ ! -f ${_logname} ]];then

touch ${_logname};

fi

#该函数打印参数1的时间戳

# perl usage: perl -e "$a=1+4;exit($a);"

cal_timestamp()

{

perl -e '

use Time::Local;

# get current time

# 参数表示,要求返还minu_num个分钟之前的时间戳yyyymmddhhmm.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%02d%02d%02d%02d.%02d",$yr,$mon,$mday,$hr,$min,$sec);

print "$beforetime"

' "$1" #把函数的第一个参数,用这种形式传递给perl

}

www.2cto.com

#最外层循环

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 oneminubef.tmp

touch -t $twominubef 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/ *$//'` #去除空格

length=`echo ${line} | awk '{print length($1);}'` #计算字符数

if [[ ${length} -gt 0 ]]; then #防止空行

newline=${line#*/} #去除文件名前面的./

filenames=$filenames" "$newline

a=`expr $a + 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值