Run multiple commands in one cron job
You can separate two or more commands with semicolons (;),
Semicolon (;): is used to separate multiple commands. This causes all commands to be executed without checking the exit status of previous commands.
We can separate two or more commands with a semicolon, which do not require checking the exit status of the previous command. E.g, you need to change the permissions of all files to 777, but you have to set 777 for the logs directory.
The cron command will look like this:
1 | 0 2 * * * chmod -R 755 /var/www/myapp; chmod -R 777 /var/www/myapp/logs |
Use this command, if you want to run the next command only then, when the previous one was successful (exit status 0). For example, you want to run backup.sh after successfully navigating to the / backup directory.
1 | 0 2 * * * cd /backup && bash backup.sh |