Difference between revisions of "Crontab"
From John Freier
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | To edit the jobs use: | |
+ | crontab -e | ||
+ | To view all jobs by user: | ||
+ | crontab -l -u {username} | ||
+ | |||
+ | This is an example of the sytax. | ||
+ | |||
+ | */5 * * * * /home/user/test.pl | ||
This is the time coding. | This is the time coding. | ||
Line 11: | Line 18: | ||
| | | | | | | | | | | | ||
* * * * * command to be executed | * * * * * command to be executed | ||
+ | |||
+ | |||
+ | Slash example: the following will run the script /home/user/test.pl every 5 minutes. | ||
+ | */5 * * * * /home/user/test.pl | ||
+ | |||
+ | |||
+ | Crontab jobs will start in / directory, make sure to cd in your first line of the bash script. | ||
+ | |||
+ | |||
+ | == Environment Variables == | ||
+ | If you want to include environment variables in the cronjob. You can add them to the top of the cron timing script. | ||
+ | |||
+ | Example | ||
+ | TARGET_DIR=/home/site/public_html | ||
+ | |||
+ | */5 * * * * deploy.sh >> log.log |
Latest revision as of 10:58, 10 December 2021
To edit the jobs use:
crontab -e
To view all jobs by user:
crontab -l -u {username}
This is an example of the sytax.
*/5 * * * * /home/user/test.pl
This is the time coding.
.---------------- 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 | | | | | * * * * * command to be executed
Slash example: the following will run the script /home/user/test.pl every 5 minutes.
*/5 * * * * /home/user/test.pl
Crontab jobs will start in / directory, make sure to cd in your first line of the bash script.
Environment Variables
If you want to include environment variables in the cronjob. You can add them to the top of the cron timing script.
Example
TARGET_DIR=/home/site/public_html */5 * * * * deploy.sh >> log.log