2012-03-08

[Linux] 使用 MD5 檢查 FTP 上傳的檔案

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

MAIL_TO="my_mail@gmail.com"
TARGET_PATH="/var/www/file/show.mp4"
FILE="upload_file"
EXTEND="mp4"

cd /home/ftp_user


# md5 file is not exist
if [ ! -f $FILE.md5 ]; then exit 0; fi

# MD5 check sum 
md5sum -c $FILE.md5 >/dev/null 2>&1
if [ "j$?" != "j0" ]; then  
 # Notice: md5 check fail 
 echo "" |mail -s "[Failed] $FILE.$EXTEND md5 check sum fail" $MAIL_TO
 rm -f ./$FILE.md5
 exit 1; 
fi

mv ./$FILE.$EXTEND $TARGET_PATH
rm -f ./$FILE.md5

exit 0;

0 回應: