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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:52:07  来源:igfitidea点击:

How to restart a service each hour?

linuxbashshellubuntustartup

提问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/

更多信息可以在http://www.ubuntututorials.com/use-crontab-ubuntu/找到