home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 40.14 Including Standard Input Within a cron Entry Chapter 40
Delayed Execution
Next: VII. Terminals and Printers
 

40.15 crontab Script Makes crontab Editing Easier/Safer

crontab
I've made mistakes with the crontab command, accidentally deleting my crontab file and not being able to get it back. I like the SunOS crontab -e command for interactive editing. So, I made a shell script that does it. To help keep me from using the system version, I store this script in a directory near the start of my PATH ( 8.7 ) ; if I really need the system version, I type its absolute pathname.
















umask
 



trap
 

||
 


${..-..}
 

cmp
 









#! /bin/sh
cmd=/usr/bin/crontab    # THE SYSTEM VERSION

# MAKE SURE EVERYONE KNOWS WHAT THEY'RE RUNNING:
echo "Running Jerry's crontab command..." 1>&2

case $# in
1)  ;;  # OK
*)  echo "Usage: `/bin/basename $0` -e | -l | -d"; exit 1 ;;
esac

case "$1" in
-[ld]) $cmd $1 ;;   # EXIT WITH STATUS OF REAL COMMAND
-e) # EDIT IT:
    umask 077
    stat=1  # DEFAULT EXIT STATUS; RESET TO 0 FOR NORMAL EXIT
    start=/tmp/CRONTAB$$s   end=/tmp/CRONTAB$$e
    trap 'rm -f $start $end; exit $stat' 0 1 2 15
    $cmd -l > $start || exit    # GET COPY OF CRONTAB
    /bin/cp $start $end
    ${VISUAL-${EDITOR-vi}} $end
    if cmp -s $start $end
    then echo "The crontab file was not changed." 1>&2; exit
    else
        $cmd $end
        stat=$? # EXIT WITH STATUS FROM REAL crontab COMMAND
        exit
    fi
    ;;
*)  echo "Usage: `/bin/basename $0` -e | -l | -d"; exit 1;;
esac

- JP


Previous: 40.14 Including Standard Input Within a cron Entry UNIX Power Tools Next: VII. Terminals and Printers
40.14 Including Standard Input Within a cron Entry Book Index VII. Terminals and Printers

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System