郵件首先用到mail.py以前屢次用到因此直接把之前的拷貝過來,若是沒有直接到https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D22Z/mail.py下載linux
拷貝mail.pygit
拷貝完mail.py還不算完成,由於最核心的地方不是mail.py而是mail.sh。由於在全部的子腳本中,用到的都是mail.sh。這個mail.sh他的做用是
編輯mail.shvim
[root@100xuni1 mail]# vim mail.sh log=$1 t_s=`date +%s` t_s2=`date -d "2 hours ago" +%s` if [ ! -f /tmp/$log ] then echo $t_s2 > /tmp/$log fi t_s2=`tail -1 /tmp/$log|awk '{print $1}'` echo $t_s>>/tmp/$log v=$[$t_s-$t_s2] echo $v if [ $v -gt 3600 ] then ./mail.py $1 $2 $3 echo "0" > /tmp/$log.txt else if [ ! -f /tmp/$log.txt ] then echo "0" > /tmp/$log.txt fi nu=`cat /tmp/$log.txt` nu2=$[$nu+1] echo $nu2>/tmp/$log.txt if [ $nu2 -gt 10 ] then ./mail.py $1 "trouble continue 10 min $2" "$3" echo "0" > /tmp/$log.txt fi fi
[root@100xuni1 mail]# pwd /usr/local/sbin/mon/mail [root@100xuni1 mail]# crontab -e * * * * * cd /usr/local/sbin/mon/bin; bash main.sh
發郵件bash