實驗目的:
時時監控公司網絡,獲取公網IP,每天早上發郵件到139郵箱提醒。
下載:
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
安裝:
#tar -zxvf sendEmail-v1.56.tar.gz
#cp -a sendEmail-v1.56/sendEmail /usr/bin
#chmod +x /usr/bin/sendEmail
常用參數:
-f 發送方
-t 接收方
-s SMTP服務器的域名或者ip
-u 郵件主題
-m 郵件內容
-a 添加附件
-cc 副本
-xu smtp驗證用戶
-xp 密碼
-v 詳細輸出
-o message-file=/file.txt 正文從文件內讀取
-o tls=yes
Shell腳本:
#!/bin/bash
#獲取公網IP地址發郵件通知
#執行者:XXX
#日期:2014/05/14
ip=`curl http://members.3322.org/dyndns/getip`
#內網郵件通知
/usr/bin/sendEmail -s xxx.xxx.xxx.xxx:25 -xu [email protected] -xp 123456 -f [email protected] -t [email protected] -u "IP地址" -o message-content-type=html -o message-charset=utf-8 -m "您的IP是:[$ip]來自:廣東省深圳市 電信"
#139郵箱通知
/usr/bin/sendEmail -s mail.139.com -xu [email protected] -xp xxxxxx -f [email protected] -t [email protected] -u "IP地址" -o message-content-type=html -o message-charset=utf-8 -m "您的IP是:[$ip]來自:廣東省深圳市 電信"
添加權限:
# chmod +x /opt/shell/ip.sh
任務計劃:
crontab -e
#每天早上06:30發139郵箱通知網絡情況
#執行者:XXX
30 06 * * * /opt/shell/ip.sh