This question has already been answered:

I didn’t do this before, but I got to write an ssh file (cron) that I need to put on the server so that it stops and starts the server every two hours. Can someone tell me where to read or tell how to do it and where to throw it?

Reported as a duplicate by members of aleksandr barakin , zRrr , insolor , user194374, Vartlok on Apr 5 '16 at 7:22 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    And what is not destiny to read what cron is and how to use it? ru.wikipedia.org/wiki/Cron - zed
  • @zed I read it. just got a little something from this all understood. how to throw it on the server, where to place it, how to write correctly. - raviga
  • You probably do not understand the essence of your TK. Apparently, you need to write a bash script that does useful work (restarting the server), upload this script to the server and create a task in cron with a call to your script with a specified frequency. - zed

1 answer 1

We save the current cron of the user to the current directory:

 crontab -l > cron.bak 

Add the nano cron.bak rule:

 30 3 * * * /home/user/bin/backup.sh > /home/user/logs/backup.log 2>&1 

All execution errors of the script itself will be written to /home/user/logs/backup.log

Overwrite cron for current user:

 crontab cron.bak 

More details can be found in one of the sources.

  • and what to write this 'cron' and how to upload it to the server and in what directory? if you want him to just stop every two hours and then raise the server again. an example of quieri to be executed. sudo service tomcat7 stop sudo service tomcat7 start - raviga
  • I use putty to connect to the server. I want to go through the specified path to the logs, writes that there is no such directory. and also writes no crontab for root - raviga
  • These are abstract paths; you need to replace them with your own. - borodatych
  • More on a subject toster.ru/q/195229 - borodatych
  • Corrected the first link, litter, did not check. - borodatych