Major Tom, This is Job Control - page 2
Acting Nice with the Linux System
Batch processing on Linux means to submit a job that will be run when the system load permits. This is normally when/proc/loadavg
is below 1.5 or
a value specified by atrun
. An example usage of batch is as
follows where exec_file.sh
is a script we want to run:
batch 1400 -f exec_file.sh
To check the status of a job the atq
utility shows the status
of jobs using the at
& batch
facilities.
at
is pretty easy but offers a lot of great options. A
simple example using the very same exec_file.sh
would look like
this:
at -f exec_file.sh 1504
There are some interesting options that go with batch
and
at
. For instance, they both have a default queue priority. The
priority scheme is letters from a-z and A-Z. Queues with higher letters run
with higher priority. Capitalized queues are treated as if they were submitted
at that time. So, to raise the queue priority of our most recent submission, we
could do this:
at -f exec_file.sh -q g 1523
Finally, we can also have the facility mail us with the -m
option.
Again, to look at current jobs in the queue use atq
. To remove
a job the atrm
command is used. The job number must be specified.
For example, if we wanted to remove job 3:
atrm 3
Last and definitely not least is cron
. The cron
facility is primarily for repetitive daily work such as backing up systems,
trimming logfiles, running certain applications or other such tasks. The
cron
facility on many systems vary and have various ways of being
implemented. All of them, however, do follow one convention: if you are a
cron
user, you can simply use the crontab -e
command
to directly edit a file that will be submitted to crond
.
The cron
facility reads out the time information from a series
of fields on each line of the cronfile. If any of these fields are omitted, it
simply truncates from the right. The fields are as follows:
minutes_after_the_hour hours days_of_the_month months_of_the_year weekdays
In other words, to schedule exec_file.sh to run every Monday morning at 3AM our entry would look like so:
00 3 * * 1 /home/mydir/exec_file.sh
If there is any possibility of messages being output by a job, it is usually a good idea to redirect it somewhere:
00 3 * * 1 /home/mydir/exec_file.sh 2>&1
The weekdays start from 0; however, years and months do not.
While this article skimmed over a lot, it is not particularly difficult to get the hang of basic job handling and prioritizing. Just write a practice script and try out all of the scheduling commands.
- Skip Ahead
- 1. Acting Nice with the Linux System
- 2. Acting Nice with the Linux System
- 3. Acting Nice with the Linux System
- 4. Acting Nice with the Linux System