VPS 重启后自动发送邮件

VPS 重启后自动发送邮件
1:yum -y install sendmail
2:检测是否能正常发送邮件 SMTP
netstat -ant (查看是否开放25号端口)
3:touch 1.sh
vi 1.sh
管理员邮箱root@zhangfangzhou.cn
---------------------------------
#!/bin/sh
sendmail -t >/dev/null 2>&1 <<EOF
to:admin@qq.com
from:root@seafile.com
subject:Your server is restarted.

Your server is restarted.
$(ifconfig eth0 |awk '/inet addr/{gsub(/addr:/,"");print $2}')
$(date +%Y/%m/%d/%H:%M:%S-%A)
EOF
---------------------------------
获取IP地址
#ifconfig 查看网卡编号(eth0,venet0:0) (文件位置:/etc/sysconfig/network-scripts)
#ls /etc/sysconfig/network-scripts
ifcfg-lo
ifcfg-venet0
ifcfg-venet0:0
ifcfg-venet0:1

#ifconfig eth0 |awk '/inet addr/{gsub(/addr:/,"");print $2}'
eth0: error fetching interface information: Device not found
#ifconfig venet0:0 |awk '/inet addr/{gsub(/addr:/,"");print $2}'
107.181.152.32

4:chmod 777 1.sh
5:vi /etc/rc.local #自启动项
6:添加/root/1.sh

评论已关闭。