crontab的使用

    xiaoxiao2021-12-14  17

    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

    转载请注明原文地址: https://ju.6miu.com/read-965387.html

    最新回复(0)