Created
June 4, 2012 05:09
-
-
Save rossomax/2866473 to your computer and use it in GitHub Desktop.
rotate log implementation by sh script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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