2024年4月28日 星期日
通知

Linux定时重启系统或服务


# crontab -e

输入以下内容


59 22 * * * reboot //每天晚上22:59重启系统
10 23 * * * service nginx restart //每天晚上23:10重启NG服务
30 2 * * * /home/web-data-backup-to-ftp.sh //每天晚上02:30执行备份脚本

:wq 保存内容

列出现有的时程表,检查一下有没有问题


# crontab -l
59 22 * * * reboot
10 23 * * * service nginx restart
30 2 * * * /home/web-data-backup-to-ftp.sh

5个*各代表什么
minute hour day month dayofweek
minute – 从0到59的整数
hour – 从0到23的整数
day – 从1到31的整数 (必须是指定月份的有效日期)
month – 从1到12的整数 (或如Jan或Feb简写的月份)
dayofweek – 从0到7的整数,0或7用来描述周日 (或用Sun或Mon简写来表示)
command – 需要执行的命令(可用as ls /proc >> /tmp/proc或 执行自定义脚本的命令)

重启cron服务


# /sbin/service crond restart (Centos 6)
# systemctl restart crond.service (Centos 7)
原创文章,转载请注明: 转载自荣耀博客
本文链接地址: Linux定时重启系统或服务

关于 荣耀博客

好记性,不如烂笔头。

随机推荐

2018031607080120 310x165.png

Centos 7.2 修改已挂载目录名

已知挂载目录名webdata1 …

发表回复