#! /bin/ksh # # Author: Mike Fleming mike@tauzero.co.uk # # runon - run specified program with current date/time set as # specified by options # # Options: # # -d Date in format YYYYMMDD # -t Time in format HHMM or HHMMSS # # programname can be a COBOL program or a script # # An alias will not necessarily work as it may only exist at the # level of the invoking shell USAGE="runon [ -d date ] [ -t time ] programname [programparams]\n\n \t-d\tDate in format YYYYMMDD\n \t-t\tTime in format HHMM or HHMMSS\n\n programname can be a script but may not work if it is an alias\n\n" CDATE= CTIME= while getopts :d:t: opt do case $opt in d) if [[ ${#OPTARG} != 8 ]] then echo Date should be YYYYMMDD return 1 fi CDATE=$OPTARG;; t) if [[ ${#OPTARG} != 4 && ${#OPTARG} != 6 ]] then echo Time should be HHMM or HHMMSS return 1 fi CTIME=$OPTARG;; *) echo Unknown option $OPTARG echo $USAGE return 1;; esac done shift $((OPTIND - 1)) if [[ "$1" == "" ]] then echo Please supply program to run return 1 fi TEMPCONFIG=$WORKDIR/cobconfig$$ if [[ "$COBCONFIG" != "" && -f $COBCONFIG ]] then cp $COBCONFIG $TEMPCONFIG elif [[ -f $COBDIR/etc/cobconfig ]] then cp $COBDIR/etc/cobconfig $TEMPCONFIG fi if [[ "$CDATE" != "" ]] then typeset -i CYYYY=$(echo "$CDATE" | cut -c1-4) typeset -i CMON=$(echo "$CDATE" | cut -c5-6) typeset -i CDD=$(echo "$CDATE" | cut -c7-8) echo "set current_year=$CYYYY" >> $TEMPCONFIG echo "set current_month=$CMON" >> $TEMPCONFIG echo "set current_day=$CDD" >> $TEMPCONFIG fi if [[ "$CTIME" != "" ]] then typeset -i CHH=$(echo "$CTIME" | cut -c1-2) typeset -i CMIN=$(echo "$CTIME" | cut -c3-4) if [[ ${#CTIME} == 6 ]] then typeset -i CSS=${echo "$CTIME" | cut -c5-6} else typeset -i CSS=0 fi echo "set current_hour=$CHH" >> $TEMPCONFIG echo "set current_minute=$CMIN" >> $TEMPCONFIG echo "set current_second=$CSS" >> $TEMPCONFIG fi SAVEDCONFIG=$COBCONFIG export COBCONFIG=$TEMPCONFIG if [[ "$(whence $1)" == "" ]] then if ! cobrun $* then echo Note: alias may not work fi else $* fi export COBCONFIG=$SAVEDCONFIG rm $TEMPCONFIG