bash 如何每小时重新启动服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24727577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to restart a service each hour?
提问by user1607016
I have a service I need to restart every hour. I'm using Ubuntu 12.04 LTS and I don't really seem to find a script suitable restarting a service based on a prefixed time setting. How do I restart the service automatically through a script?
我有一项服务,我需要每小时重新启动一次。我正在使用 Ubuntu 12.04 LTS,我似乎并没有找到适合基于前缀时间设置重新启动服务的脚本。如何通过脚本自动重启服务?
回答by keeplearningtocode
Open crontab by command:
通过命令打开crontab:
crontab -e
To run a command every 60 minutes:
每 60 分钟运行一次命令:
*/60 * * * * /path/to/command
Replace /path/to/command with command to restart service.
将 /path/to/command 替换为重新启动服务的命令。
It may look like this when you want to restart mysql:
当您要重新启动 mysql 时,它可能如下所示:
*/60 * * * * service mysqld restart
More information can be found at http://www.ubuntututorials.com/use-crontab-ubuntu/