当我们在管理服务器的时候 , 不可能永远只管理一台 , 我们管理可能是5台 ,甚至更多 , 但是我们知道这些服务器的情况呢 ? 一个个登录去看 ? 不用 , 用可以写个shell脚本 ,通过mail发送到自己的邮件就可以了。这样每天定时可以知道服务器的情况。

1、如果没有安装mail  使用yum -y install mailx

    [root@localhost ~]# yum -y install mailx

2、在/etc/mail.rc文件下面增加以下几行

    set from=smister@sina.com (发送的外部邮件地址)
    set smtp=smtp.sina.com    (发送的外部smtp服务器的地址)
    set smtp-auth-user=smister@sina.com (用户名)
    set smtp-auth-password=123456       (密码)
    set smtp-auth=login (登录方式)
3、mail命令测试
    [root@localhost ~]# echo "hello world" | mail -s "title" jieshou@smister.com
    其中title是标题,echo后面输出的是正文也可以 mail -s "title" jieshou@smister.com,然后输入正文,输入.结束


版权声明:未经博主允许不得转载。http://smister.com/post-23.html