CRONTAB:

The cron daemon, which translates to Chronological Data Event Monitor, is a program that schedules jobs to run automatically at a specific time and date. The /etc/inittab file contains all the AIX startup programs, including the cron daemon. The init process in AIX starts the cron daemon, or cron, from the inittab file during the initialization process of the operating system.

You can submit jobs, or events, to cron by doing one of the following:
Use the at and batch facilities to submit jobs for one-time execution.
Use the crontab files to execute jobs at regularly scheduled intervals (hourly, daily, weekly, and so on).

By default, cron can concurrently run 100 events of equal importance. The /usr/adm/cron/queuedefs file allows you to change this schedule.

c.200j10n120w
| |    |   |
| |    |   wait period (in seconds)
| |    nice value
| jobs
cron

At regularly scheduled intervals, cron looks for and reads the crontab files that are located in the directory /var/spool/cron/crontabs.
These files contain jobs submitted by users. For example, the file /var/spool/cron/crontabs/john contains John's jobs that are scheduled to be run by cron
The cron daemon reads the files in the /var/spool/cron/crontabs directory. The files in this directory are named for the individual users.
When changes are made to the files in the crontabs directory, the cron daemon must be notified to reread the files

/var/adm/cron/log          cron daemon creates a log of its activities
/var/adm/cron/cron.deny    Any user can use cron except those listed in this file
/var/adm/cron/cron.allow   Only users listed in this file can use cron (root user included)

crontab -l                 Lists the contents of your current crontab file
crontab -e                 Edits your current crontab file (when the file saved, the cron daemon is automatically refreshed.)
crontab -r                 Removes your crontab file from the crontab directory
crontab -v                 check crontab submission time
crontab mycronfile         submit your crontab file to /var/spool/cron/crontabs directory

crontab file format:
minute    hour    day_of_month    month        weekday        command
0-59      0-23    1-31            1-12        0-6 Sun-Sat     shell command

* * * * * /bin/script.sh        schedule a job to run every minute
0 1 15 * * /fullbackup          1 am on the 15th of every month
0 0 * * 1-5 /usr/sbin/backup    start the backup command at midnight, Mo - Fr
0,15,30,45 6-17 * * 1-5 /home/script1                                     execute script1 every 15 minutes between 6AM and 5PM, Mo - Fr
0 1 1 * * /tmp -name 'TRACE*' -mtime +270 -exec rm {} \\; >/dev/null 2>&1 it will delete files older than 9 months
                                                                          (\\; <-- double "\" needed because to interpret ";" correctly)
----------------------------

AT:

at                          submits a job for cron to run at a specific time in the future
                            (at -f /home/root/bb_at -t 2007122503)
echo "<command>" | at now   this starts in the background (and you can log off)

at now +2 mins
banner hello > /dev/pts/0
<ctrl-d>                    (at now + 1 minute,at 5 pm Friday )


/var/adm/cron/at.deny       allows any users except those listed in this file to use the at command.
/var/adm/cron/at.allow      allows only those users listed in this file to use the at command (including root).
at -l                       Lists at jobs
atq [user]                  Views other user's jobs (Only root can use this command.)
at -r                       Cancels an at job
atrm job                    Cancels an at job by job number
atrm user                   Cancels an at job by the user (root can use it for any user; users can cancel their jobs.)
atrm                        Cancels all at jobs belonging to the user invoking the atrm command

batch                       submits a job to be run in the background when the processor load is low

23 comments:

  1. Thank you for the explanation. But I want to know the command to follow the running trace when I lanch at command. I tried "mail" before it returns messages in the spool, but now i receive nothing. can you help me?????

    ReplyDelete
  2. You can try /var/adm/cron/log, because as I checked at jobs will be logged there as well.

    And you can set the standard out and err, when you run your at job.

    For example:
    root@bb_lpar: /tmp/bb # echo "find / -name "*err*" > /tmp/bb/find.out 2>/tmp/bb/find.err" | at now +2 mins
    Job root.1319448878.a will be run at Mon Oct 24 11:34:38 CEST 2011.

    root@bb_lpar: /tmp/bb # at -l
    root.1319448878.a Mon Oct 24 11:34:38 CEST 2011

    root@bb_lpar: /var/adm/cron # tail -f log
    root : CMD ( root.1319448878.a ) : PID ( 16908368 ) : Mon Oct 24 11:34:38 2011
    Cron Job with pid: 16908368 Failed

    It shows as a "Cron Job", but as you saw it was an At Job.

    ReplyDelete
  3. Thanks for shaing the article. You can find more about crontab at crontab command examples in linux

    ReplyDelete
    Replies
    1. Thanks for this good info. I found very useful data there, and I will update this page soon with it :)

      Delete
  4. Hi,
    I am facing the below messages with cron very frequently.

    Do you know how should i rectify this ?

    ! cannot access /var/adm/cron/FIFO queue Mon Mar 17 15:36:24 2012
    ! ******* CRON ABORTED ******** Mon mar 17 15:36:24 2012

    ReplyDelete
    Replies
    1. I never faced with this problem, so after Google it I have found this:
      Check if you have /var/adm/cron/FIFO file with this settings:
      root@aix14: /var/adm/cron # ls -l

      prw------- 1 root cron 0 Jun 13 14:01 FIFO


      If it is missing you can create it (don't forget p at the end):
      mknod /var/adm/cron/FIFO p

      Delete
    2. Me too have found that .
      It works fine when i remove the /var/adm/cron/FIFO and start the cron again.

      but my issue is that how can I stop to happen this again ?
      what causes to happen this ?

      Delete
    3. I would open an IBM call to find out the real cause of it.

      Delete
  5. Change the letter at your site as they are difficult to be read.

    ReplyDelete
    Replies
    1. What is the problem with that? (small or not clear typed...?)

      Delete
  6. your blog is to useful to aix admins but explanation is very less to understand for nnew admins

    ReplyDelete
    Replies
    1. Yes it may be...I describe philosophy of this blog at the main page, where I mentioned it is not intended for beginners but experienced admins. After reading few IBM Redbooks and you visit back, probably you will find this blog much helpful :)

      Delete
  7. hi...how to remove a cron job? .....(removing from file is a good way?)

    ReplyDelete
    Replies
    1. hi, yes, you open crontab file for edit (crontab -e), then remove unnecessary line(same way as in vi).

      Delete
    2. but this job is application dependant then what are the pre requsite for removing cron jobs?

      Delete
  8. hii Balazs,

    my question:

    if i add username in both cron.allow and cron.deny then which will override? whether the user will be finally allowed to schedule jobs or denied?

    once again, thanks for this amazing blog...!

    ReplyDelete
    Replies
    1. Hi Rahul,
      I just tested and cron.allow is the winner. (However a good sysadmin do housekeeping on them and will not use AIX this way :) )

      Delete
  9. I have added entry for user a_was8 in cron.allow but still user getting the error as not authorised, below snap. kindly suggest what could be the issue?
    [root@test cron]# cat cron.allow
    root
    a_was8
    adm[root@test cron]# cat cron.deny



    [root@test cron]# ls -lrt
    total 42184
    -rw-r--r-- 1 root sys 1317 Jun 17 2004 queuedefs
    -rw-r----- 1 bin cron 3 Jun 21 2004 cron.deny
    -rw-r----- 1 bin cron 4 Jun 21 2004 at.deny
    prw------- 1 root cron 0 Jan 11 2007 FIFO
    -rw-r----- 1 bin cron 0 Jan 11 2007 at.allow
    -rw-r--r-- 1 bin cron 16 Sep 19 21:10 cron.allow
    -rw-rw-r-- 1 bin bin 21521851 Sep 19 21:35 log

    [DMZ][a_was8@test a_was8]$ crontab -l
    crontab: you are not authorized to use cron. Sorry.

    ReplyDelete
    Replies
    1. Hi, did you logout and login again? (You can check if temporarily rename cron.allow what happens.)

      Delete
  10. I did logout and login again but that didn't worked. I deleted cron.allow file and recreated it again and bounce the crond but that also didn't worked.

    ReplyDelete
  11. do we have any script or some to run a conjob on 1st sunday of every month.
    can anyone help me

    ReplyDelete
  12. Hello.
    Your blog is very useful, tks.
    Aix 7.1 was reinstalled and after this the execution of crontab reply with COMMAND NOT FOUND.
    Do you know how to active the crontab service? Where is it?
    Thank you.

    ReplyDelete
  13. can any body tell me how to give permission to allow me to access crontab directory and files

    ReplyDelete