配置linux自動發送郵件
背景:學Linux已經有一段時間,期間因爲各種問題斷斷續續吧,因爲服務器不能任意登錄,所以就配置了
以下mail,當有人登錄的時候我會收到mail通知,具體操作如下
第一、配置mail.rc
vim /etc/mail.rc
add 如下內容
set from=發送郵箱例如:[email protected] smtp=smtp信息
set smtp-auth-user=發送郵箱 smtp-auth-password=密碼 smtp-auth=login
主要配置發送郵箱,此郵箱的密碼最好不要隨意更改
第二、編譯
#!
#用戶登錄報警
k=`w | wc -l`
echo $k
if [ $k -gt 2 ]; then
w |tail -3 >/root/sp/h
mail -s "有用戶登錄官網服務器" [email protected] < /root/sp/h
mail -s "有用戶登錄官網服務器" [email protected] < /root/sp/h
fi
第三、添加到任務計劃
至於多長時間監測一下 根據實際情況而定