You want to know about cron fast ? Here are some must-know commands.
Tested Configuration:
Linux: Ubuntu 18.04
Install
(cron is quite common it may already be installed)
apt-get install cron
Status
cron is a service runnging in the background. To know if itβs active, simply type :
systemctl status cron
it should show active
Configure
crontab -e
Note :
You can also try nano /etc/crontab
it should lead to the same result if you restart after you save your edit with this command : systemctl restart cron
Configuration may look like this :
# bash to use for the cron script
SHELL=/bin/bash
# is specific bin are requried
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# if an MTA like postfix is defined, email for cron bug report
MAILTO=root
# Example of job definition:
# .---------------- 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
# | | | | |
# * * * * * user-name command that will print 'test' every 30 minutes
30 * * * * root echo 'test'
# same, but here, if the script.sh generate any kind of output (standard & errors), we log this output into a cron.log
30 * * * * root /script.sh > /cron.log 2>&1
Log
If you want to know that your cron task executed, you can check the syslog:
grep CRON /var/log/syslog
Reference
Help with the * * * * * : crontab
General definitions : rosehosting
Set up : liquidweb
Change email to send the error messages : cyberciti
Check cron in your logs : askubuntu