ssh ip change
https://www.v2ex.com/t/139986
http://blog.csdn.net/nolan__roronoa/article/details/52335223
http://blog.csdn.net/rongku/article/details/50402314
1. 163 turn on smtp service (login into email box to set up)
see pic from https://www.cnblogs.com/bass6/p/5544265.html
and
blog.csdn.net/nolan__roronoa/article/details/52335223
2. install msmtp (mailPassword, use 授權碼 given by the step 1.)
sudo apt-get install msmtp
(1) 在/etc目錄下建立msmtprc的配置檔案/etc/msmtprc(msmtprc檔案預設是沒有的,要自己建立)
sudo vi msmtprc
#Accounts will inherit settings from this sectiondefaults
account 163
host smtp.163.com
port 25
from
auth login
tls off
user [email protected]
password mailPassword
logfile /var/log/msmtp.log
# Set a default account
account default : 163
(2) 建立上述配置的日誌檔案
sudo touch /var/log/msmtp.log
為了讓所有使用者都能讀寫這個日誌檔案,我們將其許可權設定為777
sudo chmod 777 /var/log/msmtp.log(3) 建立~/.msmtprc檔案
vi .msmtprc
defaultsaccount 163
host smtp.163.com
port 25
from [email protected]
auth plain
user [email protected]
password mailPassword
account default:163
logfile ~/.msmtp.log
由於password是明文,所以需要修改此檔案的訪問許可權,以下設定是隻給.msmtprc的所屬使用者讀和寫的許可權,其他人沒有任何許可權
sudo chmod 600 .msmtprc
(4) 建立上述配置中的log檔案touch ~/.msmtp.log
(5) test of sending an email:
msmtp [email protected]
test
鍵Ctrl+d
3. install mutt,
sudo apt-get install mutt
'Postfix configuration'介面,鍵盤點選箭頭->使游標移到ok,點enter
“General type of mailconfiguration”中選擇第三個”mail sent by smarthost;no localmail”,然後依次配置下去,在”Ip address or host name of the outgoingsmarthost”中,填入smtp.163.com等類似的smtp伺服器地址,然後,其他的就很簡單了(http://blog.sina.com.cn/s/blog_9ada6acf0100yh2d.html)
配置 mutt,系統全域性設定配置檔案在 /etc/Muttrc,如果使用某個系統使用者,可以在~/.muttc中設定,沒有該檔案,就自己建立。
編輯 sudo vi Muttrc
在Muttrc檔案最後新增以下內容
set sendmail="/usr/bin/msmtp"
set use_from=yes
set realname="eyun"
set [email protected]
set envelope_from=yes
4. 測試郵件傳送
echo "test" |mutt -s "my_first_test" [email protected]
installed by default of ubuntu
https://www.linuxidc.com/Linux/2015-08/121087.htm
6. 弄了一個守護程序,每分鐘檢查一下ip有沒有變,如果變了就把新ip以郵件形式發到我郵箱裡,實現的依賴:msmtp,mutt,cron。首先要把郵件配置好。ifconfig檢視本機ip, 看本機對應的是eth0/ppp0/wlp3s0/等。
具體的實現指令碼:
#!/bin/bash
IPADDRESS=$(ifconfig eth0 | sed -n 's/.*inet addr:\([^ ]*\).*/\1/p')
echo "Last check at: $(date)" >> updateip.log
if [[ "${IPADDRESS}" != $(cat ~/.current_ip) ]];then
if echo "${IPADDRESS}" | mutt -s "new ip" [email protected] ;then
echo "Ip change from $(cat ~/.current_ip) to ${IPADDRESS}" >> updateip.log
echo ${IPADDRESS} > ~/.current_ip
else
echo "Failed to send the mail, try again later." >> updateip.log
fi
fi
然後在/etc/crontab檔案最後加上一行:
* * * * * <user> bash ~/bin/updateip.sh