#! /bin/sh # $Header: /home/jpeek/.lib/at_cron/RCS/ci_crontab 2.0 2002/09/19 13:47:21 jpeek Exp $ ### ci_crontab - use RCS 'ci' command on your crontab file ### Usage: ci_crontab [directory-to-store-in] ## ## Crontab files can be hard to configure and easy to lose. ## This program uses the RCS ci command to check in a copy of the ## crontab file. If you name a directory on the command line, it stores ## the file there. Otherwise it tries the directories listed in $dirs. ## The RCS file will be put in that directory (or its RCS subdirectory, ## if there is one). Crontab files that haven't changed aren't checked ## in. This script will call the file crontab.hostname, where hostname ## is the local part of the hostname (foo.bar.com would be crontab.foo) ## ## This is a great command to run automatically from the crontab ## file, itself... or anytime you change the crontab. For example: ## alias ecron='crontab -e; ci_crontab' ## ## This script is in the public domain. Do whatever you want with it. ## If you have comments or suggestions, please email them to me. ## --Jerry Peek, jpeek@jpeek.com, 19 September 2002 # CONFIGURE these four lines (PATH may not be set by cron): basename=/bin/basename # Gets root of a pathname cat=/bin/cat # Outputs a file to stdout ctcmd=/usr/bin/crontab # Program for accessing crontab file rcs=/usr/bin # Directory where RCS commands live dirs="$HOME/.lib/at_cron $HOME/.lib $HOME/lib $HOME" # Explained above temp=/tmp/CI_CRONTB$$ # Temporary copy of crontab file stat=1 # Default exit status (reset to 0 before normal exit) trap '/bin/rm -f $temp; exit $stat' 0 1 2 15 hostname=`uname -n` case "$hostname" in *.*) hostname="`expr $hostname : '\([^.]*\)\.*'`" ;; # Keep local part esac file=crontab.$hostname # Check each directory in $1 (if any) and $dirs: does it exist and is # it writable? If so, that's the place we'll store the RCS file: for dir in $1 $dirs do if [ -d "$dir" -a -w "$dir" ] then cd "$dir" || exit # If old $file exists, move it out of the way: if [ -s $file ] then echo "`$basename $0`: renaming old $file to #$file" >>$temp mv $file \#$file || exit fi # If get here, have found a $file. We'll exit before loop ends: $ctcmd -l > $file || exit # Get copy of crontab file $rcs/rcsdiff -ko $file >>$temp 2>&1 # Compare (ignore keywords) case $? in 0) stat=0 ;; # No change. Quit, no output 1) $cat $temp # Show command outputs $rcs/rcs -l $file || exit # Lock RCS so we can check in $rcs/ci -m'automatic checkin' $file || exit stat=0 # If ci OK, set exit status ;; *) $cat $temp 1>&2 echo "`$basename $0` quitting: rcsdiff $file failed?" 1>&2 ;; esac exit # If we found a file, break loop and exit (at the trap) fi done