crontab的使用

来源:互联网 发布:aoi编程技工 编辑:程序博客网 时间:2024/06/04 17:44

crontab是在liunx配置定时任务,触发shell脚本

配置好的文件会存在于:/var/spool/cron/tabs  下面的root文件


 root身份登录到命令行

1.输入crontab -e

2.按下a键进入到编辑模式

3.输入 0 */1 * * * /home/work/start-service.sh

4.同时按下ctrl+c退出编辑模式

5.按下shift+: 输入wq 退出 crontab


查看cron状态


sudo  service cron status 

开启cron


sudo /etc/init.d/cron start

关闭cron


sudo /etc/init.d/cron stop

重启cron


sudo /etc/init.d/cron restart


 crontab用法

crontab –e : 修改 crontab 文件,如果文件不存在会自动创建。 
crontab –l : 显示 crontab 文件。 
crontab -r : 删除 crontab 文件。
crontab -ir : 删除 crontab 文件前提醒用户。

样例

10* * * * /opt/bi/push/pushPretreatment/bi2.sh>>/opt/bi/push/log/localhost_bi2.log

20 * * * * /opt/bi/push/pushPretreatment/bi3.sh>>/opt/bi/push/log/localhost_bi3.log

1 12 * * * /opt/bi/push/pushPretreatment/bi4.sh>>/opt/bi/push/log/localhost_bi4.log

1 3 * * * /opt/bi/push/pushPretreatment/bi5.sh>>/opt/bi/push/log/localhost_bi5.log




0 0