Linux Exercise: Scheduling
User crontab files
Login as tux1. Make a crontab file that runs the date command every five minutes, and saves the output in /home/tux1/cron-datefile.
- $ crontab -e
*/5 * * * * date >> /home/tux1/cron-datefile
Note that you are not editing the crontab file directly, but rather a copy in /tmp. Once you exit your editor, the file will be checked and copied to the right location.
Also note that you can choose which editor to use by setting the $EDITOR shell variable.
- $ crontab -e
Look at your crontab file to see if it was installed correctly.
- $ crontab -l
Also try to view your crontabfile using cat. Is this allowed?
- $ cd /var/spool/cron
- Wait five minutes, then look at the datefile. Does your cron job work? (While waiting you can already continue with the rest of the exercises.
System crontab files & anacron
Login as root. Look at the file /etc/crontab and the files in /etc/cron.d. Also look which RPMs put the files in /etc/cron.d.
- # vi /etc/crontab
- # ls -l /etc/cron.d
- # for file in /etc/cron.d/*; do rpm -qf $file; done
You will notice that different RPMs have put the files here. They were not part of the RPM that put the crontab command on your system, for instance.
Look at the files /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly. What kind of jobs are listed here? Again, look from which RPMs these files originate.
- # ls -l /etc/cron.hourly
- # ls -l /etc/cron.daily
- # ls -l /etc/cron.weekly
- # ls -l /etc/cron.monthly
Look at the /etc/anacrontab file.
- # cat /etc/anacrontab
Crontab security
As root, create a file /etc/cron.deny. Add the user tux2 to this file.
- # vi /etc/cron.deny
tux2
- # vi /etc/cron.deny
Login as tux2 and try to make a crontab. Does this work?
- $ crontab -e
at
Login as tux1. Use at to schedule a job in five minutes. This job is to create a file "atfile" in your working directory, with the current date and time, in the home directory of tux1.
- $ at now + 5 minutes
- at> date >> ~/atfile
- at> Ctrl-D
Look at the at queue
- # atq
Wait five minutes and see if your job ran. Also take a look at the at queue again.
- # cat atfile
- # atq
at security
- Similar to cron, create an /etc/at.deny file and list tux2 in that file. See if tux2 can submit at jobs.