FTP自动上传脚本,并发送邮件提醒

Shell/Python   ftp脚本  

在内外网隔离的环境下,内网需要提交客户端到外网,必须通过运维。
脚本实现功能:当内网指定目录有提交新文件时、自动上传、不重复上传、上传完毕,生成下载地址发送给需要收到通知的人

#!/bin/bash
# 存放新客户端目录
ftpdir=/home/clinet  
# 存放已上传客户端目录
ftpbak=/home/clinet/complete  
# 接收邮件提醒的邮箱地址,多的话用空格隔开
mails=(admin@imdst.com)  
for client in $ftpdir/*  
do  
        if [ ! -f $client ]
                then 
                        echo "client no found"
                        exit
        fi

        echo "begin put $client ,please wait ......"

        for a in $ftpbak/*
        do
                if [ $a == $client ];then
                                for mail in ${mails[@]} ; do
                                     echo "$a is exits,$a not upload" |mutt -s "$a is exits"  $mail
                                done
                                exit
                fi
        done

        status=`cat /tmp/ftp_status.log`

        if [[ $status -eq 1 ]];then
                echo "client is uploading...."
                exit
        elif [[ $status -eq 0 ]];then
                echo "1" > /tmp/ftp_status.log
                echo "open ftp.imdst.com 1021
user ftpuser dc3*******662e  
binary  
put $client  
bye  
" | ftp -n 
                mv $client ../complete/
                for mail in ${mails[@]} ; do
                    echo "$client transfer finish,http://dl.imdst.com/$client" |mutt -s "client put complete" $mail
                done
                echo "0" > /tmp/ftp_status.log
        fi
done