#!/bin/ksh # @(#) Work with crontab #..# systems: #..# sites: #..# level: #..# publish: y #..# keys: #..# date: #..# vers: 1.4 25/Nov/2005-12:57 [ $0 = ${0#/} ] && this=$(pwd -H)/$0 || this=$0 tag=${0##*/} tmp=/tmp/${tag}$$ #rm -f $tmp* find /tmp -xdev -name "${tag}*.sav" -mtime +1 -exec rm {} \; 2>/dev/null & usage="Usage: $tag [-w] [-m] " while [ $# -gt 0 ]; do case "$1" in -v|-x) set "$1" ;; -vi) lockvi $this; exit ;; -view) view $this; exit ;; -about) echo "$tag was written by David Ledger" echo "dledger@ivdcs.co.uk" echo "Free to use at your own risk" echo "Copyright 2005" exit ;; -ver) ver=$(egrep '#..#[ ]*vers:' $this) ver=${ver#"${ver%%[1-9]*}"} print ${ver%%[!0-9.]*} exit ;; -h) echo "" echo "$usage" echo "" echo "$tag edits a users crontab file, changing the first line" echo "that would be found by an 'ed' // search. The time" echo "on that line is changed to be 1 minute ahead of the" echo "current time. If '-w' is given, after the edit and re-" echo "submission to cron, the script sleeps until the next" echo "minute before exiting. If '-m' is specified, the same" echo "wait is made, and after a further two seconds, 'mailx' is" echo "invoked to read the mail resulting from the cron job." echo "" echo "As well as changing the minute and hour fields, $tag" echo "changes the day, month and weekday fields to today, so" echo "that test entries will not run every day, but only at the" echo "requested date/time in years when the weekday also" echo "matches." echo "" echo "" exit ;; -w*) wait=1 ;; -m*) wait=1; mail=1 ;; *) job="$(echo "$1" | sed 's,/,\\/,')" ;; esac shift done [ "$job" ] || { print "$usage"; print "Need to specify cron job"; exit; } nxtmin() { set -A nm $* [ ${nm[4]} -lt 59 ] && nm[4]=$((nm[4] + 1)) || { [ ${nm[3]} -lt 23 ] && { nm[3]=$((nm[3] + 1)) nm[4]=0 } || { nm[3]=0 nm[4]=0 } } echo ${nm[*]} } set -A dt `date "+%y %m %d %H %M %S %u"` [ ${dt[5]} -gt 58 ] && { sleep 2 set -A dt `date "+%y %m %d %H %M %S"` } echo ${dt[*]} set -A nm `nxtmin ${dt[*]}` crontab -l > $tmp cp ${tmp} ${tmp}.sav && print -u2 "Copy of existing saved as ${tmp}.sav" || exit ed $tmp <