Tuesday, June 14, 2011

System sheduler - CRON Notes


Features:


1. Permits scheduling of scripts(shell/perl/python/ruby/PHP/etc.)/tasks on a per-user basis via individual cron tables.

2. Permits recurring execution of tasks

3. Permits one-time execution of tasks via 'at'

4. Logs results(exit status but can be full output) of executed tasks

5. Facilitates restrictions/permissions via - cron.deny,cron.allow,at.*


Directory Layout for Cron daemon:

/var/spool/cron - and sub-directories of to store cron & at entries

/var/spool/cron/atjobs - houses one-off, atjobs

- 787546321.a - corresponds to a user's atjob

/var/spool/cron/crontabs - houses recurring jobs for users

- username - these files house recurring tasks for each user


Cron command:

crontab - facilitates the management of cron table files

-crontab -l - lists the cron table for current user -

- reads /var/spool/cron/crontabs/root


###Cron table format###

m(0-59) h(0-23) dom(1-31) m(1-12) dow(0-6) command

10 3 * * * /usr/sbin/logadm - 3:10AM - every day

15 3 * * 0 /usr/lib/fs/nfs/nfsfind - 3:15 - every Sunday

30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean

1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1

m(0-59) h(0-23) dom(1-31) m(1-12) dow(0-6) command

Note: (date/time/command) MUST be on 1 line

m = minute(0-59)

h = hour(0-23)

dom = day of the month(1-31)

m = month(1-12)

dow = day of the week(0-6) - 0=Sunday

Note: each line contains 6 fields/columns - 5 pertain to date & time of execution, and the 6th pertains to command to execute

#m h dom m dow

10 3 * * * /usr/sbin/logadm - 3:10AM - every day

* * * * * /usr/sbin/logadm - every minute,hour,dom,m,dow

*/5 * * * * /usr/sbin/logadm - every 5 minutes(0,5,10,15...)

1 0-4 * * * /usr/sbin/logadm - 1 minute after the hours 0-4

0 0,2,4,6,9 * * * /usr/sbin/logadm - top of the hours 0,2,4,6,9

1-9 0,2,4,6,9 * * * /usr/sbin/logadm - 1-9 minutes of hours 0,2,4,6,9

Note: Separate columns/fields using whitespace or tabs


###Create crontabs for root & unixcbt###

Note: ALWAYS test commands prior to crontab/at submission

11 * * * * repquota -va >> /reports/`date +%F`.quota.report

Note: set EDITOR variable to desired editor

export EDITOR=vim


###unixcbt - execute quota -v###

#!/usr/bin/bash

HOME=/export/home/unixcbt

quota -v >> $HOME/`date +%F`.unixcbt.quota.report

#END

Note: aim to reference scripts(shell/perl/python/ruby/PHP,etc.) instead of the various characters

Note:

Default Solaris install creates 'at.deny' & 'cron.deny'

You MUST not be included in either file to be able to submit at & cron entries

Conversely, if cron.allow and at.allow files exist, you MUST belong to either file to submit at or cron entries

No comments:

Post a Comment



Follow storageadmiins on Twitter Follow storageadmiins on Twitter