linux ftp自动脚本,Linux/Unix实现自动ftp的shell脚本

#!/bin/ksh

. /tbill/app/.profile

sqlplus err/err123@billing @/tbill/data/recyclepath/tmp/ftp_file_data.sql

onInit()

{

USERHOME=$HOME

if [ -f "/tbill/data/recyclepath/tmp/autoftp.conf" ];then

. /tbill/data/recyclepath/tmp/autoftp.conf

echo machine $host > $USERHOME/.netrc

echo login $user >> $USERHOME/.netrc

echo password $passwd >> $USERHOME/.netrc

chmod 600 $USERHOME/.netrc

echo =============================

echo "host=$host"

echo "user=$user"

echo "password=x"

echo "remote dir=$remoteDir"

echo "source dir=$sourceDir"

echo "success dir=$backupDir"

echo "pattern=$pattern "

echo =============================

return 0

else

return 1

fi

}

showinfo()

{

echo NAME

echo "      autoftp  -automatic upload file to ftp server"

echo SYNOPSIS

echo "      autoftp"

}

checkdir()

{

if [ ! -d $sourceDir ];then

echo "ERROR!    source dir $sourceDir is not found!"

return 1

fi

if [ ! -d $backupDir ];then

mkdir $backupDir

fi

return 0

}

putFiles()

{

ftp -i $host << EOF

cd $remoteDir

mput $@

bye

EOF

}

#############  main procedure ###################

DIRNAME=`date +%Y%m%d`

if [ $# -eq 1 -a "$1" = "-v" ] ;then

showinfo

exit

fi

#======================================================

#backup .netrc file

if [ -f ~/.netrc ]; then

mv ~/.netrc ~/.netrc.old

fi

#======================================================

onInit

if [ $? -ne 0 ];then

echo "ERROR!    autoftp.conf not exist! please prepare it"

exit 1

fi

checkdir

if [ $? -ne 0 ];then

exit 1

fi

#begin ftp

date

echo "begin ftp"

cd $sourceDir

while read file;

do

if [ -f $sourceDir$file ]; then

touch "$file.chk"

mv $file "$file.txt"

putFiles "$file.txt $file.chk"

mv $file.txt /tbill/data/recyclepath/tmp/$backupDir

rm $file.chk

echo "put $file.txt $file.chk done!"

fi

done <

`ls -1|grep "$pattern"`

!

date

echo "ftp end"

#=============================================if [ -f ~/.netrc ]; then  rm -f ~/.netrcfiif [ -f ~/.netrc.old ]; then  mv ~/.netrc.old ~/.netrcfi#============================================###*************************************配置文件host=10.100.5.6user=noservpasswd=noservsourceDir=/tbill/data/other_path/backupDir=`date +%Y%m%d`remoteDir=./#使用正则表达式描述pattern="^report.*"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值