ubuntu – 如何使用crontab每4小时重启一个进程?

有人可以告诉我如何使用crontab每4小时重启一个进程吗?我有一个Starbound服务器正在运行(这是最近出现的像terarria这样的游戏)并且它占用了大量资源,所以我想要杀死这个过程,然后每6小时重启一次.

我认为我需要在crontab中做的是:

杀了-9 | grep starbound_server
cd / home / steam / starbound / linux64&& screen -S starbound -d -m ./launch_starbound_server.sh

但我不确定这一点,也不了解时间.

我希望有一个人可以帮助我 :)

crontab就是这样的.
# .---------------- 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

因此,如果您希望每隔4小时运行一次脚本,则必须将此行添加到crontab文件中.

* */4 * * * user-name command to be executed

要每4小时(零分钟)运行一次脚本,您必须将此行添加到crontab文件中.

0 */4 * * * user-name command to be executed

编辑(回答评论):

是的,我相信这是正确的,但作为我自己,我通常会为此执行单独的文件,例如,script.sh以保持清洁.

例如内容

#!/bin/sh

# Kill 1
screen -X -S | grep starbound kill 

# Kill 2
kill -9 | grep starbound_server

# Change directory  
cd /home/steam/starbound/linux64

# Start the server again 
screen -S starbound -d -m ./launch_starbound_server.sh

您可以将其保存到您喜欢的位置并使用:

chmod +x yourcript.sh

使其可执行,然后将其添加到crontab.

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...