–> Use crontab files to schedule jobs on a periodic basis
–> Use the at command to schedule a job or series of jobs at some time in the future
–> Use the batch command to schedule jobs in a queue, to alleviate immediate system demand
Responsible for running scheduled jobs
crontab command events (regularly scheduled jobs)
at command events (on timeonly execution at a specific time)
batch command events (run when CPU load is low)
–> Used to start regularly occuring jobs
–> Schedule is defined in /var/spool/cron/crontabs/$USER
–> Files to control users’ crontab privileges
/var/adm/cron/cron.deny – list user who cannot use crontab
/var/adm/cron/cron.allow – list user who can use crontab
–> An empty cron.deny exists by default
crontab -l – list the jobs in the crontab file
minutes(0-60), hour(0-24), date(1-31), month(1-12), dayofweek(0Sun-6Sat), command /w FullPath,
10,30 * * * 4 /full/path/job
10min and 30min past every hour on every Thursday
Note: The comma just means “and”
# crontab -e – To edit crontab file:
# crontab -l > /tmp/crontmp
# vi /tmp/crontmp
# crontab /tmp/crontmp – submits this file as the new crontab file
The at and batch Commands: (One time jobs only)
The at command submits a uniquely occurring job for cron
# at now +2 mins
banner hello > /dev/tty3
job user.time.a will be run at date
# batch – (no time scheduled since it runs when the CPU load is low)
banner hello > /dev/tty3
Note: There is no time scheduled with the batch command since it runs when the CPU load is low.
Note: You must press Enter at the end of each line. You can type in several commands after each one pressing enter.
Controlling “at” Jobs:
To list “at” jobs
at -l [user]
To cancel a job:
at -r job
atrm [job | user]
Note: By typing in the user name it will remove all jobs for that user. Otherwise, you must type in the full job number to remove a specific job.
root.962649853.a Mon Jul 3 14:44:13 EDT 2006
at -r root.962649853.a (remove this job number)
Note: The files “at.allow” and “at.deny” can be used to control who can schedule jobs.
Have a copy of user’s crontab files
Have a copy of /etc/inittab
Note: /etc/inittab starts daemon processes including cron when booting
Note: If the cron daemon is not running then you can schedule jobs but they would never be started.
Q: I tried to set a crontab entry to kick off a program to run when the 1st of the month is a Sunday. It runs more often than that. What am I doing wrong? 0 0 1 * 0 /home/team01/myscript
A: You are not doing anything wrong. It is the way cron works. Normally, the fields are read with “and” statement. But, when there is a entry other than “*” in field 3 (day of the month) and field 5 (day of the week), cron treats just those two fields with a “or” comparison. This means, in your example, “1” represents the 1st of the month, and the last 0 represents Sunday. Cron read this as “if it is the 1st or it is Sunday” start the job.
Q: How do I start the skulker script?
A: It is normally started from the crontab file. In root’s crontab, the entries are already there for skulker but are commented out. Uncomment the lines and let it run.
Q: Is skulker safe?
A: Generally speaking yes. But, since this script removes files with root authority, you should review the script to make sure it is ok for your environment. You can edit the script to customize it, but be careful. A dumb error could be disastrous. Remember it runs with root authority.
Q: What happens if there is a cron.allow and a cron.deny file at the same time?
A: Cron.allow is used. It is more restrictive. Make sure root is in the cron.allow file or root can’t use crontab either.
Q: When would I want to use crontab vs. at?
A: Crontab is used for recurring jobs. If you want the job to run everyday, for example, put it in crontab. If you want a job to run only once, use at. “at” creates a queue of jobs. Once they run, they are removed from the queue.
Q: What happens to jobs that are scheduled to run, but the machine was down at the time? When the machine reboots, will the job execute?
A: It depends whether it was a crontab job or an “at” job. “at” jobs will run. Once the scheduled time passes, it will run at the first opportunity. However, a crontab job will not run. It will run the next time, it is scheduled to run.
Q: Is it better to use kill with no options or kill with the -9 option?
A: It is usually better to try to kill processes without the -9 option first. This is a gentler way to terminate jobs. If you are terminating a parent process, the child processes with be terminated first giving the parent process a chance to update the process table. Then the parent is terminated. If you use kill -9 (and you might be force to if the kill doesn’t work) the processes, both parent and child, will end. However, the process table sometimes does not clean up leaving “orphaned” or “zombie” processes. The processes are terminated, but may continue to hold a process table slot. They will not use any other system resources however. If you try to terminate the processes to clean up the table, AIX will say that it could not find the process (because it has already been terminated). The only way to update the process table is to reboot. It is not something that must be done right away, but it should be done. Try to avoid this by starting with a plain old “kill” first before resorting to the kill -9.
Q: What does kill -15 do?
A: Kill -15 is the default kill option. When you don’t specify an option, -15 is used.