17
2019
02

使用cron实现路由器定时重启

在/etc/crontabs/root下面添加任务


10 2 * * * sleep 5 && touch /etc/banner && reboot   //每天2点10分路由器自动重启



计划任务列表的格式:


[minute] [hour] [day of month] [month] [day of week] [program to be run]

其中各个参数的取值范围是:

minute(0-59)

hour(0-23)

day of month(1-31)

month(1-12)

day of week(0-7,0 or 7 is Sun)


每个参数里的取值可以有4种间隔符:

* 表示任意

- 表示范围

, 表示枚举多个值

/ 表示每隔

例如:


      周一到周五每天晚上23:30执行ruijieclient -k

      30 23 * * 1-5 /bin/ruijieclient -k

 

      每天每隔10分钟执行date

      */10 * * * * date


       30 21 * * * /usr/local/etc/rc.d/lighttpd restart 

      上面的例子表示每晚的21:30重启apache。

 

      45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart 

     上面的例子表示每月1、10、22日的4 : 45重启apache。 


     10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart 

    上面的例子表示每周六、周日的1 : 10重启apache。 


     0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart 

    上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启apache。 


     0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart 

    上面的例子表示每星期六的11 : 00 pm重启apache。 


     * */1 * * * /usr/local/etc/rc.d/lighttpd restart 

    每一小时重启apache 


    * 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart 

    晚上11点到早上7点之间,每隔一小时重启apache 


    0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart 

    每月的4号与每周一到周三的11点重启apache 


    0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart 

    一月一号的4点重启apache 


另外每次执行完成任务后系统会发送信息给你,如果你不想收,可以在每条执行语句后面加:

>> /dev/null 2>&1




« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。