10 cronrun - convenience features to run commands in task scheduler environment
14 cronrun [I<OPTIONS>] <I<COMMAND>> [I<ARGS>]
16 Run I<COMMAND> in a way most scheduled jobs are intended to run, ie:
20 =item Set computing priority (nice(1), ionice(1)) to low
22 =item Delay start for random amount of time, thus avoiding load-burst when multiple jobs start at the same time
24 =item Allow only one instance at a time (by locking)
32 =item --random-delay, -d I<SEC>
34 Delay program execution at most I<SEC> seconds.
35 Default is to wait nothing.
39 Wait for the lock to release.
40 By default cronrun(1) fails immediately if locked.
46 Lock is based on C<CRONJOBID> environment, or I<COMMAND> if C<CRONJOBID> is not set.
48 If C<CRONJOBID> is set, STDIO goes to syslog too, in the "cron" facility, stdout at info level, stderr at error level.
49 If not set, STDIO is not redirected.
55 =item F<~/.cache/cronrun>
57 Lock files stored in this directory.
67 Recommended practice is to set C<CRONJOBID=something> in your crontab before each C<cronrun ...> job definition.
99 -*) echo "$scriptname: unknown option: $1" >&2
108 lockdir
=/var
/run
/lock
/cronrun
110 lockdir
=~
/.cache
/cronrun
/locks
112 cmd_hash
=`echo -n "${CRONJOBID:-$1}" | md5sum | cut -c1-32`
115 # delay random amount of seconds
116 sleep $
[RANDOM
% ($random_delay_sec + 1)]
120 if [ -n "$CRONJOBID" ]
122 syslog_ident
=$LOGNAME.
${CRONJOBID//\//.}
123 exec 1> >(exec logger
-p cron.info
-t "$syslog_ident" -s 2>&1) 2> >(exec logger
-p cron.error
-t "$syslog_ident" -s 1>&2)
127 # scheduled jobs are likely good to run at low priority
128 renice
-n 19 -p $$
>/dev
/null
134 lockfile
=$lockdir/$cmd_hash
135 exec {lock_fd
}>>"$lockfile"
136 flock
--exclusive --nonblock $lock_fd
142 echo "cronrun: waiting on lock..." >&2
143 flock
--exclusive $lock_fd
149 echo "cronrun: lock acquired" >&2
155 # ---- lock acquired ----