首页 > 代码库 > Linux-No.03 Linux 设置定时任务发送邮件功能
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="kaka02@17guagua.com" r1="mobilewebsvr@17guagua.com" 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
Linux-No.03 Linux 设置定时任务发送邮件功能
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。