Friday, December 9, 2016

cron Daemon IV: Scheduling Processes

cron Daemon IV: Scheduling Processes 

Scheduling Processes 

Using cron to Manage Scheduled User Jobs


Users on your system can create their own schedules using a crontab file that is associated with
their user account.



Unlike system crontab files, which are saved in /etc, user crontab files are 
stored in

/var/spool/cron/tabs



If a user has created a crontab file, it will be saved under his or her username in this directory.


Before proceeding, I should point out that not all Linux system administrators want to allow 
their users to do this. If allowing users to make their own crontab files and run programs on a
schedule makes you nervous, you can lock the system to prevent them from doing so. To do this,
you use an approach similar to that used when working with the at daemon.


The cron daemon will read the 


/etc/cron.allow 


and


/etc/cron.deny 


files when it starts up to determine who can and who can’t create crontab schedules.


By default, only the

/etc/cron.deny 


file is created automatically, and it contains only one restriction by default for the guest user
account.


All other users are allowed to create crontab files to schedule jobs. 

If you create an 


/etc/cron.allow 


file, then only the users in that file will be allowed to create crontab files; all others will
be denied.



With that out of the way, let’s discuss how users can create their own crontab files. To do this,
they can use the


crontab –e 


command. After this command has been entered, the vi editor is opened with a new, blank crontab file loaded.



In this file, the user simply adds lines for each job they want to run using the syntax we
reviewed previously. For example, in Figure 13-13, the tar command is run at 5:10 p.m. every day
to back up the user’s home directory to a file named ~/homebak.tar.



The file is edited using standard vi commands and keystrokes, which you learned earlier in
this book. (I told you knowing how to use vi would come in handy!) When you’re done, exit vi
and save the file. After doing so, a new crontab file for the user is created in


/var/spool/cron/tabs


as shown in the next example.



In addition, the cron service is reloaded so the new configuration can be applied.



openSUSE:/ # ls /var/spool/cron/tabs/
rtracy
openSUSE:/ # cat /var/spool/cron/tabs/rtracy
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.wwzr9t installed on Tue Dec 2 22:31:44 2014)
# (Cronie version 4.2)
10 17 * * * /bin/tar -cvf ~/homebak.tar ~



In this example, I used the cat command to view the tux user’s crontab file. However, you can
also use the


crontab –l 


command to display your user’s crontab file.


In addition, you can use the


crontab –r 


command to remove your user’s crontab file






LX0-104 Exam Objectives (L)

No comments:

Post a Comment