一个专业运
维技术分享!

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  



微信扫描下方的二维码阅读本文

赞(6) 打赏
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。小柳实验室 » FTP自动上传脚本,并发送邮件提醒

相关推荐

  • 暂无文章

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

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏