SEQRES 1 357 GLU VAL LEU ILE THR GLY LEU ARG THR ARG ALA VAL ASN 2MNR 106 SEQRES 2 357 VAL PRO LEU ALA TYR PRO VAL HIS THR ALA VAL GLY THR 2MNR
5.9 Playing Nicely with Others in a Shared Environment
5.9.2 Scheduling Recurring Activities with cron
The cron daemon, crond, is a standard Unix process that performs recurring jobs for the system and individual users. System activities such as cleanup of the /tmp directory and system backups are typically functions controlled by the cron daemon. Normal users can also submit their own jobs to
cron, assuming they have permission to run cron jobs. Details about cron permissions are found in the
crontab manpage. Since the at and batch commands, which are discussed later, are also controlled by
cron, most systems are configured to allow users to use cron by default.
5.9.2.1 Submitting jobs to cron using crontab
Usage: crontab -[options] file
Submission of jobs to cron is done using the crontab command. crontab -l > file places the current contents of your crontab into a file so you can edit the list. crontab file sends the newly edited file back and initializes it for use by cron. crontab -r deletes your current crontab.
cron processes the contents of all crontab 's and then initiates jobs as scheduled. A crontab entry as produced by crontab -l looks like:
# Format of lines:
#min hour daymo month daywk cmd
50 2 * * * /home/jambeck/runme
This entry runs the program runme at 2:50 A.M. every day. An asterisk in any field means "perform this function every time." In this entry, all output to either STDOUT or STDERR is mailed to user
jambeck 's email account on the machine where the cron job ran.
5.9.2.2 Using cron to schedule a recurrent database search
What if your group performs DNA sequencing on a daily basis, and you want to use the sequence- alignment program BLAST to compare your sequences automatically against a nonredundant protein database? Consider this crontab entry:
01 4 * * * find /data/seq/ -name "*.seq" -type f -mtime -1 -exec /usr/bin/csh /usr/local/bin/blastall -p blastx -d nr -i '{' ";'
This automatically runs at 4:01 A.M. and checks for all sequences that have been modified or added to the database in the last 24 hours. It then runs the BLASTX program to search your copy of the
nonred undant protein sequence database for matches to your new sequences and mails you the results. This example assumes you have all the necessary environment variables set up correctly so that BLAST can find the necessary scoring matrixes and databases. It als o uses a default parameter set, which may need to be modified to get useful results. Once you get it configured correctly, all you have to do is browse through your email while you drink your morning coffee.
5.9.2.3 Scheduling processes with batch and at
Usage: at -[options] time
Usage: batch -[options]
The batch and at commands are standard Unix functions and are commonly available on most systems. Jobs are submitted to queues, and the queues are processed by the cron daemon; jobs are governed by the same restrictions as crontab submissions. The batch command assigns priorities to jobs running on the system. Using batch allows a system administrator to sort jobs by priority—high to low—thereby allowing more important jobs to run first. Unless the system has a mechanism to kill interactive jobs that exceed a specified time limit, this use of the batch queue relies on users to work in a cooperative manner. On larger systems the function of batch is usually replaced by more complicated queuing systems. You need to get information from your system administrator about which batch and at queues are available.
at allows you to submit a job to run at some specified time. batch sequentially runs jobs whenever the machine load drops below a specified level and the number of concurrent batch jobs has not been exceeded. Once you initiate at or batch, all command-line entries are considered part of the job until you terminate the submission with a Ctrl-D keystroke. Like cron, any STDOUT and STDERR generated by the job are mailed to you, so you at least get notified of error conditions. Here are the common options:
-q queuename
Specifies the queue. By default, at uses the "a" queue; batch uses the "b" queue. -l
Causes at to list the jobs current in the specified queue. -d jobid
Tells at to delete a specified job. -f filename
Instructs at to run the job from a file rather than standard input. -m
Time can be now, teatime, 7:00 P.M., 7:00 P.M. tomorrow, etc. Check the manpage for more details.
As an example, let's say that you want your boss to think you were slaving away at 3:00 A.M. Simply send her mail at 3:07 A.M. Even if you don't plan on being awake, it's no problem. At the at command prompt, just type:
> at 3:07am
Mail -s "big breakthrough" boss@wherever < /home/jambeck/news <Ctrl-d>