Linux Sysadmin Test Prep
cron
cron
Tips
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 to be executed`
Commands
Command | Action |
---|---|
crontab -l | Lists all the user's cron tasks |
crontab -e | Edit for current user (root if sudo) |
crontab -e -u daniel | Edit for user daniel |
crontab -r | Removes entry from spooler, but not crontab file |
Troubleshooting
No environment variables! Use absolute paths!
ps ax | grep cron
start
,restart
, and checkstatus
of cron.service* * * * * /bin/echo "cron works" >> /tmp/cronTest
(User syntax doesn't have the User field, root does.)Test script without cron.
Check permissions for script and any redirections.
Don't suppress output while debugging.
2>&1
to a file which you have write access instead of /dev/null.2>&1 >> cron.out
will append to user's home directorygrep cron /var/log/syslog
Add
cron.crit /var/log/cron.log
in /etc/rsyslog.d/50-default.conf andsudo /etc/init.d/rsyslog reload
Quiz
- Run
quiz
with the argumentcron
This quiz matches strings instead of evaluating commands, so input must be entered without extra whitespace in the format specified by the question.