#!/bin/sh # # chmod +x on this file to run # usage "./rotate filename" # Will rotate a log (or any file) # and increment a .[0-8] after it. # # Usefull for rotating large /var/log/messages logs # to only keep a weeks work (or more) # # Use at your own risk # PATH="/usr/bin:/sbin:/usr/sbin:/bin" filelist=$* for file in $filelist do files="$files `echo $file | /usr/bin/egrep -v '\.[0-9]$'`" done for file in $files do for oldfile in 8 7 6 5 4 3 2 1 0 do if [ -f $file.$oldfile ] then /bin/mv $file.$oldfile $file.`/usr/bin/expr $oldfile + 1` fi done done for file in $files do if [ -f $file ] then /bin/cp $file $file.0 /bin/cat /dev/null > $file fi done