// Not Recommended: Opens cron job list for current logged in user [Not recommended, very hard to manage]
crontab -e
// Add this line to cron job file (Run a job every 5 minutes - run by current logged in user)
*/5 * * * * /path/to/script-or-program >> log_file.txt
// Recommended : Open cron job list for root
vim /etc/crontab
// Specify a user to run the cron job can be root, user_a, user_b
*/5 * * * * <user> /path/to/script-or-program >> log_file.txt
// Check whether cron job has run or not
sudo vim /var/log/syslog
// or
sudo grep "your_cron_job.php" /var/log/syslog
https://www.inmotionhosting.com/support/website/cron-jobs/did-cron-job-run
# m h dom mon dow user command
│17 * * * * root cd / && run-parts --report /etc/cron.hourly
│25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
│47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
│52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
when you scheduled cron job make sure to schedule after these time, or else cant see log
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
00 19 * * 1,3,5 /home/user/somejob.sh
No comments:
Post a Comment