Schedule Reboot By Crontab

1.Parameters

crontab基本格式 : 

*  *  *  *  *  command 

分 时 日 月 周 命令 

第1列表示分钟1~59 每分钟用*或者 */1表示 

第2列表示小时1~23(0表示0点) 

第3列表示日期1~31 

第4列表示月份1~12 

第5列标识号星期0~6(0表示星期天) 

第6列要运行的命令 

2. Examples

crontab -e

#每天凌晨5点重启VPS,请添加下面这行
 
0 5 * * * /usr/sbin/shutdown -r now > /dev/null 2>&1
 
#每周一凌晨5点重启VPS,请添加下面这行
 
0 5 * * 1 /usr/sbin/shutdown -r now > /dev/null 2>&1
 
#每6小时重启一次VPS,请添加下面这行
 
0 */6 * * * /usr/sbin/shutdown -r now > /dev/null 2>&1

指令输入完毕后,保存退出(:wq)

/etc/rc.d/init.d/crond stop

/etc/rc.d/init.d/crond start

3. General usages

cd /var/spool/cron                 # centos

cd /var/spool/cron/crontabs        # debian

crontab -l                         # list schedule tasks under current user

crontab -u username -l             # list a specific user's schedule task

cat /etc/crontab  /etc/cron.d/*    # list system schedule tasks

ls -l /etc/cron.weekly/            # list weekly schedule tasks

systemctl list-timers              # list *.timer files
Scroll to Top