2013-12-08 37 views
8

Qualcuno potrebbe dirmi come riavviare un processo ogni 4 ore utilizzando crontab? Ho un server Starbound in esecuzione (che è un gioco come Terarria che è uscito di recente) e richiede molte risorse, quindi mi piacerebbe terminare il processo e riavviarlo ogni 6 ore.Come riavviare un processo ogni 4 ore usando crontab?

Quello che penso che avrei bisogno di fare in crontab è:

kill -9 | grep starbound_server cd/home/vapore/starbound/linux64 & & schermo -S starbound -d -m ./launch_starbound_server.sh

Ma io non sono sicuro di questo e non capisco il tempo thingy neanche.

Spero che qualcuno mi può aiutare :)

+1

Eventuali duplicati: http://stackoverflow.com/ domande/11562804/running-cron-job-on-linux-ogni-6-ore – aste123

risposta

22

crontab funziona in questo modo.

# .---------------- 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 

Quindi, se si desidera eseguire il proprio script ogni minuto su intervalli di 4 ore, è necessario aggiungere questa riga al file crontab.

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

per eseguire lo script una volta ogni 4 ore (sul minuto zero), dovreste aggiungere questa riga a crontab file.

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

Edit (Risposta di commentare):

Sì, credo che questo è corretto, ma come mi faccio di solito file separato per questo, per esempio, script.sh per mantenere le cose pulite.

Ad esempio, con contenuti:

#!/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 

È possibile salvare nella posizione che ti piace ed impiego:

chmod +x yourcript.sh 

per renderlo eseguibile, e quindi aggiungerlo al crontab.

+0

Wow grazie, in realtà non riesco a credere quanto bene lo abbiate spiegato! Vorrei poterti sopravanzare. Se non mi dispiace chiedere un'altra domanda, questo sarebbe corretto: * */4 * * * my_user_name schermo -X -S | grep starbound kill && kill -9 | grep starbound_server && cd/home/vapore/starbound/linux64 && schermo -S starbound -d -m ./launch_starbound_server.sh – user3079979

+0

Ehi impressionante, tu sei il mio salvatore! Ma screen -X -S | grep starbound kill non sembra funzionare, ho cercato su Google ma non riesco a trovare nulla su come cercare/trovare uno schermo e poi ucciderlo. Voglio cercarlo perché a volte non vuole essere ucciso e devo mettere pid.screen. – user3079979

+0

Hai provato "killall -9 starbound"? – m4gix1

1

A condizione di aver installato lo script di avvio del server starbound in /etc/init.d

http://www.bubblews.com/news/1749423-starbound-server-start-script

E si chiamarono starbound.sh

Poi, aggiungere una riga nel /etc/crontab come questo:

0 /4 * * * root /etc/init.d/starbound.sh restart

(NOTA: questo è nel caso in cui il server starbound è iniziata da root: verificare che il server stesso lascia cadere i suoi privilegi all'avvio se non ha bisogno di loro)

+2

Dovrebbe essere '0/4 * * * root /etc/init.d/starbound.sh restart' da eseguire una volta ogni ora. Non ogni minuto di ogni 4a ora. Penso che sia chiaramente ciò che l'OP vuole. – naktinis

Problemi correlati