Linux-No.03 Linux 设置定时任务发送邮件功能
1、定时任务
crontab -l crontab -e /sbin/service crond start //启动服务 /sbin/service crond stop //关闭服务 /sbin/service crond restart //重启服务 /sbin/service crond reload //重新载入配置 /sbin/service crond status //查看服务状态 */1 * * * * /opt/shell/load-check.sh 00 03 * * * /opt/shell/download_log.sh * */1 * * * /opt/shell/diskfree.sh ps -ax | grep cron
2、发送邮件
#!/bin/bash percent=`df -k | grep -v Filesystem| awk ‘{print int($5)}‘` for each_one in $percent do if [ $each_one -ge 90 ];then echo $each_one email_date=$(date "+%Y-%m-%d %H:%M:%S") echo "email_date : "$email_date >> /opt/disk.log echo "server : 120.132.38.102" >> /opt/disk.log df -h >> /opt/disk.log from_name="shaohua" from="[email protected]" r1="[email protected]" to="<$r1>" #email_title="120.132.38.102 Disk Critical" email_content="/opt/disk.log" email_subject="120.132.38.102 Disk Critical" echo -e "To: ${to}\nFrom: \"${from_name}\" <${from}>\nSubject: ${email_subject}\n\n`cat ${email_content}`" | /usr/sbin/sendmail -t rm -rf /opt/disk.log break fi done
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。