#!/bin/ksh # # Function to rotate files a la logrotate but in shell, removing the # dependency on logrotate, and making it more cross platform. # # Tested both with ksh93 and bash # # # This software is provided as is with no warranties. # Use at your own risk. # # Redistribution and use with or without modification, are permitted. # This applies worldwide. # Yves Dorfsman, 2010 # function rotateFile { filename=$1 let keep=9 if [[ -z $filename ]] ; then echo "need filename." >&2 return 1 fi let counter=keep while [[ counter -gt 1 ]] do let nextvalue=counter-1 [[ -f ${filename}.$nextvalue ]] && mv -f ${filename}.$nextvalue ${filename}.$counter let counter=nextvalue done [[ -f $filename ]] && mv -f $filename $filename.1 } rotateFile $1 exit $?