Special File Types   «Prev 

How to Edit and Control Access to Crontab - Exercise

Using crontab on Linux

Objective: Use the crontab command to schedule a system shutdown.

Exercise scoring

This exercise is not scored. When you have completed the exercise, click the Submit button to continue with the course.

Instructions

Taking advantage of periodic processes is vital to effective system management with UNIX. In this exercise, you will use crontab to schedule a system shutdown. Before you can use crontab, 1) you must first assume root privileges.
2) Then, you view the contents of a file that will be the crontab entry source, and
3) finally you will use crontab. Start the simulation below and work through the situation presented.
1) Text 1 2) Text 2 3) Text 3 4) Text 4 5) Text 5 6) Text 6 7) Text 7 8) Text 8
  1. Use the |||(S7)su|||(S0) command to assert root privileges
  2. Assert root privileges by entering su
  3. Use |||(S1)rootpass|||(S0) as the root password.
  4. Enter the Password: rootpass
  5. Use the |||(S7)ls -l|||(S0) command to view the contents of the /var/spool/cron directory.
  6. View contents of the command you entered
  7. ls -l /var/spool/cron
  8. Use the |||(S7)ls -l|||(S0) command followed by the proper directory name.
  9. View contents
  10. ls -l /var/spool/cron
  11. Note the backup and shutdown files. You will be using the shutdown file. Before you run |||(S7)crontab|||(S0) on this file, use the |||(S7)head|||(S0) command to view /var/spool/cron/shutdown.
  12. Head command
  13. head /var/spool/cron/shutdown
  14. Type |||(S1)head /var/spool/cron/shutdown|||(S0) to view this file.
  15. Notice that cron will shut down on Monday at 6:55 p.m. You can tell this because the first entry indicates the minutes (55), and the second entry indicates the hours (18, or 6 p.m.). Finally, the number 1 after the two asterisks means Monday. Remember that 0 is Sunday. Thus far, you have viewed only a raw text file. You are now ready to use crontab to schedule this event for root. Use crontab to enter this event into the list of events for cron to process. For safety's sake, be sure to specify root as the user, then provide the full path to the shutdown file.
  16. Execute the crontab command
  17. crontab -u root /var/spool/cron/shutdown
  1. The crontab command would need the -u option with root specified as the user. Follow this with the full path to the shutdown file
    /var/spool/cron/shutdown
    
  2. Verify that cron is ready to execute the command at the correct time. Do this by listing the scheduled cron events for root.
  3. List scheduled cron events
  4. crontab -u root -l
  5. Use the -u option for the crontab command with root specified as the user. Follow this with the -option to obtain a list of entries to be processed by cron.