* * * * * /sbin/reboot
前面五个*号代表五个数字,
顺序分别是:分、时、日、月、星期,它们数字的取值范围和含义如下: 分钟 (0-59) 小时 (0-23) 日期 (1-31) 月份 (1-12) 星期 (0-6)//0代表星期天
For details see man 4 crontabs
Example of job definition:
.—————- minute (0 – 59)
| .————- hour (0 – 23)
| | .———- day of month (1 – 31)
| | | .——- month (1 – 12) OR jan,feb,mar,apr …
| | | | .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
| | | | |
* * * * * user-name command to be executed
操作方式:
1、通过SSH已root用户登录系统
2、设置开机启动 chkconfig crond on
3、启动服务 service crond start
4、编辑 crontab -e
5、按i 输入 30 3 * * * /sbin/reboot (表示晚上3点半自动重启) 按esc 按shift+zz
6、重启 service crond restart
参考资料
第一、安装Crontab
一般我们服务器都默认安装过的,直接执行第二步就可以,但是有些发行版是没有安装的,所以我们不管如何直接先安装一次,如果已经安装或者没安装过的,也无所谓。
1、centos
yum install vixie-cron crontabs
chkconfig crond on
service crond start
2、debian
apt-get install cron
/etc/init.d/cron restart
这里根据我们服务器的环境,然后安装crontab,且启动。
第二、编辑定时自动脚本
crontab -e
在ssh中执行脚本,然后编辑文件。
0 1 * * * /sbin/reboot
丢进去这个脚本,表示每天凌晨1点重启服务器。编辑完毕之后:wq保存退出。
第三、保存退出重启生效
/etc/rc.d/init.d/crond stop
/etc/rc.d/init.d/crond start
这样执行后就可以生效,可以实现我们需要的定时自动重启服务器的功能。