kenics.net

Technical notes on perl, python, php, sql, cgi, c/c++, q/kdb+, unix/shell, revision control tools, data structures & algorithms, and their applications into web services and other various forms of software engineering.

crontab autosys job scheduler

 
################### 
####  crontab  #### 
################### 
 
crontab -l 
crontab -e 
crontab -r 
 
min hour date month day cmd 
15  0-9  *    *     1-5 <cmd>   ## * means all applicable, like 0-59 
 
e.g. 
0,30,40-45 * * * 0-6 /bin/echo afile >/tmp/`/bin/date "+\%Y\%m\%d"`.log   ## "%" must be escaped 
*/15 * * * 0-6  <cmd>                                                     ## every 15-min 
 
( BAD EXAMPLE ) 
20 1 1-7 4 0 <cmd>   ## looks like it captures the first sunday in April at 01:20 AM 
                     ## but it runs every day from 1st-7th April and all Sundays in April 
==> correctly 
20 1 1-7 4 * /bin/test `date +\%w` =0 && <cmd> 
 
 
* */2 * * * <cmd>    ## looks like it runs at every even number hour 
                     ## it runs every minute of every even number hour 
===> correctly 
0 */2 * * * <cmd> 
 
### always escape "%" with back slash 
e.g. 
20 23 * * 1-5 <script> 1>/tmp/log.`/bin/date "+%\Y\%m\%d.\%H\%M\%S"` 2>&1     ## will create /tmp/log.YYYYMMDD.HHMMSS 
 
### unix/linux loads the crontab schedule one minute prior, e.g. the job for 17:54 is loaded at 17:53. Thus if you set a job less than a minute away, often for the purpose of testing, it is too late. 
 
 
#################### 
###   autosys    ### 
#################### 
 
$ autorep -j <job_name>      # shows the latest job status 
$ autorep -j <job_name> -d   # shows the detail status 
$ autorep -j <job_name> -q   # shows the job definition 
                             # "command" is what actually runs 
                             # "machine" is where the job runs 
                             # "owner" is where/who can edit the job 
                             # google for other fields 
$ autorep -M <machine_name>  # often used to un-alias the autosys logical hostname 
 
 
OI: ON_ICE 
OH: ON_HOLD 
RU: RUNNING 
SU: SUCCESS 
TE: TERMINATED    #  term_run_time: xx # min 
IN: INACTIVE 
AC: ACTIVE        # this is when you have start_times and condition tag set, and one gets satisfied and waiting for the other 
ST: STARTING      # you see this momentarily when job is starting 
RE: RETRYING 
FA: FAILED 
 
 
$ sendevent -E STARTJOB -j <job_name>        # run a job 
$ sendevent -E FORCE_STARTJOB -j <job_name>  # force start 
$ sendevent -E DELETEJOB -j <job_name>       # delete a job 
$ sendevent -E JOB_ON_HOLD -j <job_name>     # put on hold  (JOB_OFF_HOLD for unlock) 
$ sendevent -E JOB_ON_ICE -j <job_name>      # put on ice   (JOB_OFF_OCE for unlock) 
 
===> diff btw ice and hold is, when unlocked, hold will run whatever missed runs whereas ice wont 
 
$ sendevent -E CHANGE_STATUS -j <job_name> -s SUCCESS 
 
 
###  to see the list of timezone  ### 
$ autotimezone -l 
 
 
###  install/update a job definition  ### 
 
$ autorep -q -j <job_name> >/tmp/definition_file   ## contains the definition of <job_name> 
                                                   ## edit it, call it def_file2 
 
$ jil < /tmp/def_file2                             ## if it's new, prefix should be "insert_job" 
                                                   ## otherwise, should be "update_job" 
                                                   ## --owner <user_id> option is useful 
###  job tupes in autosys 
c : normal crontab type of jobs 
b : box type jobs, group job which has child dependent process 
f : file watch job 
 
###  box_name 
box_name: foo-bar-weekend-job  ==> you can specify box_name to a group job. all jobs for the box must run SU for it to run next time. 
                               ==> to know the composite of a box, $ autorep -q -j <job_name> 
 
NOTE: do not set start_times tag at both the box job def and its member jobs, with diff values, because it generally waits for the box job, resulting in unintended job start timing. 
 
 
There are many other configurable parameters. 
 
(ref)  http://autosys-tutorials.blogspot.jp/2011/04/autosys-quick-reference.html 
 
---- example params from the above link ---- 
 
insert_job: template job_type: c 
box_name: box1 
command: ls -l 
machine: localhost 
owner: username_that_updated_the_job@name_of_host_where_you_updated_the_job 
permission: gx,ge,wx,we,mx,me 
date_conditions: 1          # this means do look at start_times tag. enabled this when you use both start_times and condition tags. 
days_of_week: all 
start_times: “15:00, 14:00″ 
run_window: “14:00 - 6:00″ 
condition: s (job1) 
description: “description field” 
n_retrys: 12 
term_run_time: 60          # min, 1440 = 24hr, often you see 1400 
box_terminator: 1 
job_terminator: 1 
std_out_file: /tmp/std_out 
std_err_file: /tmp/std_err 
min_run_alarm: 5 
max_run_alarm: 10 
alarm_if_fail: 1 
profile: /tmp/.profile            # specify the environmental var 
 
 
 
#################### 
####   at cmd    ### 
#################### 
 
/usr/bin/at -m -t HHMM -f <sh_cmd_file> 
 
-m    # email to the executor when executed 
-l    # list at queue = same as /usr/bin/atq 
-t    # takes [[CC]YY]MMDDhhmm[.ss] format 
-f    # takes the cmd in the file (only .sh is executed) 
 
e.g. 
$ at -m -t 11272312 
at> pwd 
at> Ctr-D 
job 1 at Wed Nov 27 23:12:00 2013 
 
$ at -l 
1       Wed Nov 27 23:12:00 2013 a mel 
 
$ atrm 1      # atrm <job_id> 
$ atq 

 

  1. 2013-11-25 00:26:47 |
  2. Category : unix
  3. Page View:

Google Ads