In the example demonstrated below, I am using a backup script for the game Valheim on Linux, but anything can be used here.
- First run “crontab -e” this will go into edit mode for the scheduled task we are creating.
- If it asks you to select an editor choose your favorite, mine is nano.
- Navigate to the last blank line and use 1 line for each task that should be performed. (I will have 2)
- Line #1 Reads: At 3:30 am, every day, start the script “ValheimBackup.sh” (which takes a backup of Valheim) and write the log output to a specific location.
- Line #2 Reads: At 3:35 am, every day, perform a reboot of the server.
Note: Make sure you leave the asterisks “*” for time values you do not use, otherwise the computer will think you wanted something else or an error will occur.
30 3 * * * /usr/local/bin/valheimbackup.sh > /var/log/valheimbackup-cron.log 2>&1
35 3 * * * /sbin/shutdown -r
Other examples
Run a script that performs an action after restarting the machine
@reboot /usr/local/bin/TheBestApp.sh
Run the backup script that performs daily at midnight
@daily /usr/local/bin/valheimbackup.sh > /var/log/valheimbackup-cron.log 2>&1
Leave a Reply