码迷,mamicode.com
首页 > 系统相关 > 详细

Linux-No.03 Linux 设置定时任务发送邮件功能

时间:2014-09-25 19:05:09      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:ar   for   sp   art   on   c   log   linux   ad   

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 设置定时任务发送邮件功能

标签:ar   for   sp   art   on   c   log   linux   ad   

原文地址:http://my.oschina.net/shma1664/blog/318647

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!