目的:帮别人写的一个自动ftp脚本,涵盖md5校验、上传、备份三个功能
#!/bin/sh
HOST="b.2222.org" #上传的主机
USER=gsftp #用户
PASSWORD=slslsl1111 #密码,这三项均可修改
cd /gsftp
#获取md5文件信息,并判断是否存在,不存在则退出脚本
UPLOAD1=`cat *.md5`
if [ $? -eq 0 ]; then
echo "MD5 file exist, content:$UPLOAD1"
else
echo "MD5 file not exist"
exit
fi
#获取zip文件的md5码,预备和上传过来的md5比较;如果zip文件不存在则退出脚本
UPLOAD2=`/usr/bin/md5sum *.zip | awk '{print $1}'`
if [ $? -eq 0 ]; then
echo "zip file exist, md5 :$UPLOAD2"
else
echo "zip file not exist"
exit
fi
#定义uptoftp函数,负责上传到服务器
function uptoftp() {
#上传部分
lftp -u ${USER},${PASSWORD} sftp://${HOST} <
#cd ${DEST_DIR}
#put ${TARGET}
put $file1 $file2
bye
EOF
#备份文件
if [ $? -eq 0 ]; then
echo "done"
mv * /opt/gsftpbak/ && echo "backup to
/opt/gsftpbak"
else
echo " Can't upload to $HOST,Please check $HOST ."
fi
}
#获取上传文件名称
file1=`/bin/ls -l /gsftp/*.md5| awk '{print $9}'`
file2=`/bin/ls -l /gsftp/*.zip| awk '{print $9}'`
#比较md5,如一致则上传,不一致也上传,在日志增加错误信息
if [ "$UPLOAD1" = "$UPLOAD2" ]; then
echo "Starting to sftp to ${HOST}"
uptoftp
else
echo "MD5 error ! Please check file. But still upload it."
uptoftp #如果以后需要修改为md5一致再上传的话,删除本行即可
fi
阅读(2232) | 评论(0) | 转发(0) |