1 #!/bin/bash 2 #监控系统剩余内存 3 4 free_mem=`free -m | awk 'NR==3{print $NF}'` #获取当前的内存值 5 chars="current memory is $free_mem" 6 if [ $free_mem -lt 100 ] 7 then 8 echo $chars | tee /tmp/messagers.txt #屏幕输出提示,并写入文件 9 mail -s "`date +%F-%T`$chars" test@15512345678@163.com
1 #在这使用本地mail客户端,以及第三方邮件服务商:163.com 配置mail.rc,将linux本地作为邮件客户端 2 #echo -e "set from=15512345678@163.com smtp=smtp.163.com\nset smtp-auth-user=zhoulei smtp-auth-password=123456 smtp-auth=login" >>/etc/mail.rc3 #测试发送邮件,(服务器能上网)4 #echo "this is test" >/tmp/test.txt5 # mail -s "title" 15512345678@163.com