Beruflich Dokumente
Kultur Dokumente
Unix has two built-in schedulers. These schedulers allow you to setup
programs to run at any date, or time in the future unattended. The two
schedulers are Cron, and At.
Cron Job
Users crontabs are kept in the file /var/spool/cron/crontabs/
The root user has a crontab setup by default. You can see
whats scheduled to run via the cron scheduler, by using
the command crontab l, while logged
# id
uid=0(root) gid=0(system) groups=2(bin),3(sys),7(security),8(cron),10(audit),11(lp)
#
# crontab l
.
#0 3 * * * /usr/sbin/skulker
#45 2 * * 0 /usr/lib/spell/compress
#45 23 * * * ulimit 5000; /usr/lib/smdemon.cleanu > /dev/null
0 11 * * * /usr/bin/errclear -d S,O 30
0 12 * * * /usr/bin/errclear -d H 90
0 15 * * * /usr/lib/ras/dumpcheck >/dev/null 2>&1
# SSA warning : Deleting the next two lines may cause errors in redundant
#SSA warning : hardware to go undetected.
01 5 * * * /usr/lpp/diagnostics/bin/run_ssa_ela 1>/dev/null 2>/dev/null
0 * * * * /usr/lpp/diagnostics/bin/run_ssa_healthcheck 1>/dev/null 2>/dev/null
# SSA warning : Deleting the next line may allow enclosure hardware errors to go undetected
Cron Job
0 2 3 2 0 /home/bob/program1
There are six fields in a crontab configuration. They are as follows, from left to right.
1 The minute of the hour the job will run (0-59)
2 The hour of the day the job will run (0-23)
3 The day of the month the job will run (1-31)
4 The month of the year the job will run (1-12)
5 The day of the week the job will run (0-6) 0 = Sunday.
6 Command/program to run.
In our example at the top of the page a program called program1 which resides in the directory
/home/bob, will run at 2am, on February 3rd, on Sunday.
You can also use an asterick, *, in a specific field to denote, run every whatever.
The pound sign, #, will disable that job/program from running via cron.
3
Cron Job
Setting the EDITOR system variable to a specific editor
will tell the crontab editor which editor to use to edit the
crontab.
# ls -l /usr/bin/vi
-r-xr-xr-x 5 bin bin
# export EDITOR=/usr/bin/vi
# echo $EDITOR
/usr/bin/vi
# date
Fri Sep 11 10:40:18 EDT 2009
#
# crontab e
45 10 * * * /usr/bin/sleep 60 &
# ps -ef | grep -i sleep
root 372746 340172 0 10:41:23 pts/0 0:00 grep -i sleep
#
Cron
You can view the status of a past cron job by viewing
the /var/adm/cron/log file.
# ps -ef | grep -i sleep
root 372754 1 0 10:45:00
- 0:00 /usr/bin/sleep 60
# cd /var/adm/cron
# pwd
/var/adm/cron
# ls -l log
-rw-rw-r-- 1 bin
bin
# tail log
root : CMD ( /usr/lpp/diagnostics/bin/run_ssa_healthcheck 1>/dev/null 2>/de
v/null ) : PID ( 372876 ) : Fri Sep 11 10:00:00 2009
Cron Job with pid: 372876 Successful
root : CMD ( /usr/lpp/diagnostics/bin/run_ssa_encl_healthcheck 1>/dev/null
2>/dev/null ) : PID ( 372940 ) : Fri Sep 11 10:30:00 2009
Cron Job with pid: 372940 Successful
root : CMD ( /usr/bin/sleep 1000 & ) : PID ( 393470 ) : Fri Sep 11 10:45:00 2009
Cron Job with pid: 393470 Successful
Cron Job
# at 11:11 today
sleep 60
job root.1252681860.a at Fri Sep 11 11:11:00 2009
# at -l
root.1252681860.a
#
- 0:00 sleep 60
Cron Job
At jobs status are also logged to the
/var/adm/cron/log file.
# tail /var/adm/cron/log
root : CMD ( /usr/lpp/diagnostics/bin/run_ssa_encl_healthcheck 1>/dev/null
2>/dev/null ) : PID ( 372940 ) : Fri Sep 11 10:30:00 2009
Cron Job with pid: 372940 Successful
root : CMD ( /usr/bin/sleep 1000 & ) : PID ( 393470 ) : Fri Sep 11 10:45:00
2009
Cron Job with pid: 393470 Successful
root : CMD ( /usr/bin/errclear -d S,O 30 ) : PID ( 393258 ) : Fri Sep 11 11
:00:00 2009
root : CMD ( /usr/lpp/diagnostics/bin/run_ssa_healthcheck 1>/dev/null 2>/de
v/null ) : PID ( 405614 ) : Fri Sep 11 11:00:00 2009
Cron Job with pid: 405614 Successful
Cron Job with pid: 393258 Successful
root : CMD ( root.1252681860.a ) : PID ( 372838 ) : Fri Sep 11 11:11:00 2009
Cron Job with pid: 372838 Successful
#
Cron Job
- The file /var/adm/cron/cron.deny is used to list users who are not authorized
to use cron.
- The file /var/adm/cron/cron.allow is used to list users who are authorized to
use cron.
- The file /var/adm/cron/at.deny is used to list users who are not authorized to
use at.
- The file /var/adm/cron/at.allow is used to list users who are authorized to use
at.
8