一个专业运维
技术分享网站!

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  
历史上的今天
七月
29
    哇哦~~~,历史上的今天没发表过文章哦
赞(5) 打赏
未经允许不得转载:小柳实验室 » FTP自动上传脚本,并发送邮件提醒
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏