寫教學的最大目的是教會未來的自己

ubuntu server 開機自動發信通知(使用gmail)

參考資料

http://tschci.blogspot.tw/2009/04/ubuntu.html

http://fourdollars.blogspot.tw/2009/08/ssmtp-gmail.html

 

最近弄到一台server

因為是寄放在別人的機櫃裡,因為有些原因我想知道 server 何時重開機

所以寫了 下列教學

 

 

1. 安裝 SMTP

apt-get install ssmtp

2. 設定SMTP

vim /etc/ssmtp/ssmtp.conf 加入下列資料

AuthUser=user.name@gmail.com
AuthPass=password
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES

 

3.測試

 echo "This is a test mail." | mail -s "test mail" user.name@gmail.com

有收到信就表示成功了

 

4.撰寫shell script

vim mail.sh

#!/bin/sh

t=$(date +%Y%m%d%H%M%S )
sudo echo "標題"$t |mail -s "open server"  [email protected]

5.測試 shell script

sh mail.sh

檢查是否收到信

 

6.設定自動執行

cp mail.sh /etc/init.d

sudo update-rc.d mail.sh defaults 99 1

 

完成收工

 

Post to Twitter Post to Plurk Post to Facebook Send Gmail

發表迴響

Copyright © 2024. All Rights Reserved.

歡迎光臨
初音