Skip to content

Instantly share code, notes, and snippets.

@rossomax
Created June 4, 2012 05:09
Show Gist options
  • Select an option

  • Save rossomax/2866473 to your computer and use it in GitHub Desktop.

Select an option

Save rossomax/2866473 to your computer and use it in GitHub Desktop.
rotate log implementation by sh script
#!/bin/sh
# Usage: rotatelog.sh [-zcn] level logfiles...
while getopts zcn flag; do
case $flag in
z) compress="/usr/bin/gzip"; ext=".gz";;
c) compress="/usr/bin/compress"; ext=".Z";;
n) ECHO="echo";
esac
done
shift `expr $OPTIND - 1`; n=$1; shift
for file in $*; do
n1=$n
while [ $n1 -gt 1 ]; do
n2=`expr $n1 - 1`
$ECHO mv $file.$n2$ext $file.$n1$ext
n1=$n2
done
$ECHO cp $file $file.1; $ECHO cp /dev/null $file
[ $compress ] && $ECHO $compress $file.1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment