Contact us |
llm2-lab9-exercise-1In this exercise you will first make sure that the cron package is installed on your system, next you will make sure it is running, then you will explore some of it’s configuration files and finally you will use cron to schedule tasks of your own.To make sure the cron software is installed 1. Log in to the system as root 2. Use the rpm command to query the system for the cron software. Type: root@serverXY root# rpm -q vixie-cron Write down the output of the command? 3. Use the rpm command to view the list of all the files/directories that the came with cron. Type: root@serverXY root# rpm -ql vixie-cron To start, stop and reload crond 1. Use the service command to make sure that the cron daemon (crond) is running. Type: root@serverXY root# service crond status Write down the output? If the cron daemon is not running start it with: root@serverXY root# service crond start 2. If you need to restart crond for any reason type: root@serverXY root# service crond reload Reloading cron daemon configuration: OK To examine cron’s configuration files 1. On most Linux systems cron’s configuration files are: /etc/crontab, /etc/cron.allow, /etc/cron.deny. Examine the files: root@serverXY root# cat /etc/crontab ………………………
02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly ………………… From your output what is the value of the MAILTO variable in the /etc/crontab file? Are the /etc/cron.deny and /etc/cron.allow files present? 2. Individual user crontab files are stored in /var/spool/cron/<USERNAME>. Examine the files in that directory and list them below? To edit /etc/crontab 1. Make a note of the current time on your system: Type: root@localhost root# date Mon Sep 23 18:41:41 PDT 2002 What is the current time on your system? 2. Open up the /etc/crontab file with your favorite editor and add an entry that will cause crond to send out a false (test) boot message to all logged on users five minutes after the time you are done editing the file. Go to the bottom of the file and add an entry like the one below using the current time on your system. Save the file when done. 46 18 * * * root shutdown -k now 3. What do each of the fields you just added do? e.g. the first field -46 means the 46th minute of the hour. To edit your personal crontab file You will create some empty files in the junk directory. As the user ying create the files temp1 temp2 temp3 in the junk folder. 1. Log in to the system as the user “ying” 2. Examine ying’s current crontab file. Type: ying@serverXY ying$ crontab -l no crontab for ying 3. While in ying’s home directory, cd to the junk folder and create some files. Type: ying@serverXY ying$ cd junk && touch temp1 temp2 temp3 4. Use the ls command to list the contents of the junk folder. 5. Create a crontab entry for ying to delete all the files in the junk folder every minute, of everyday. Type: ying@serverXY junk$ crontab -e
NOTE: “crontab -e” will attempt to use your default editor. Usually “vi”. So you have to use the usual vi commands to edit your crontab file. e.g. You have to first type “<i>” to insert any text and <ESC> to exit the insert mode. 6. Examine the junk folder to see if the files temp1 etc are still there. 7. Write down the command to create a new entry in your crontab file to send the output of the date command to terminal/ console you are currently working in, five minutes after you start editing the crontab file. HINT: To find out your current console/terminal use the “tty” command. 8. Log out of the user “ying’s” account. To prevent users from using the crond facilities 1. Log in to the system as root. 2. Check if the /etc/cron.allow and the /etc/cron.deny files exist on your system. 3. Create them if they don’t exist. Type: root@serverXY cron# cat > /etc/cron.deny << over > ying > > over 4. Also create the /etc/cron.allow. Type: root@serverXY cron# touch /etc/cron.allow 5. Now as the root user, try to list ying’s crontab file. Type: root@serverXY cron# crontab -u ying -l What happened? 6. Use your text editor to comment out the line with ying’s name in /etc/cron.deny: root@serverXY root# vi /etc/cron.deny
7. Attempt to list ying’s crontab file again. Type: root@serverXY root# crontab -u ying -l You (ying) are not allowed to use this program (crontab) See crontab(1) for more information 8. The previous step failed again because you need to explicitly place an entry for the user “ying” in the /etc/cron.allow file for her to be able to use crond. Type: root@serverXY root# vi /etc/cron.allow And add the name “ying” in the file. Save the file and exit your editor. 9. As the root user attempt to edit ying’s crontab again. What is the command to do this? What happened this time?
|
Login... |