linux定时重启服务器

需求说明

需要每天定时凌晨重启服务器

脚本实现

1. linux 终端输入crontab -e,添加定时任务脚本命令

[root@localhost ~]# crontab -e

 

2. 在文件末尾追加

0 0 * * * /sbin/reboot;

 

3. 重启服务让定时任务生效

systemctl restart crond

 

4. 配置定时任务开机自启

查看服务是否开机自启

systemctl list-unit-files|grep crond.service

 

如果没有开机自启,设置开机自启

systemctl enable crond

 

THE END