]> Zhao Yanbai Git Server - minix.git/commitdiff
rotate script
authorBen Gras <ben@minix3.org>
Fri, 12 Aug 2005 13:28:37 +0000 (13:28 +0000)
committerBen Gras <ben@minix3.org>
Fri, 12 Aug 2005 13:28:37 +0000 (13:28 +0000)
commands/scripts/Makefile
commands/scripts/rotate.sh [new file with mode: 0755]

index 94297165e59b2c6871c0e5ae181efef94b9e4d47..e5f28f0ab7d14e51346c60d5e2589221e71680ed 100755 (executable)
@@ -34,6 +34,7 @@ usr:  \
        /usr/bin/mkdep \
        /usr/bin/mkdist \
        /usr/bin/setup \
+       /usr/bin/rotate \
        /usr/bin/floppysetup \
        /usr/bin/spell \
        /usr/bin/srccrc \
@@ -105,6 +106,9 @@ clean:
 /usr/bin/floppysetup:  floppysetup.sh
        install -m 755 -c -o bin $? $@
 
+/usr/bin/rotate:       rotate.sh
+       install -m 755 -c -o bin $? $@
+
 /usr/bin/setup:        setup.sh
        install -m 755 -c -o bin $? $@
 
diff --git a/commands/scripts/rotate.sh b/commands/scripts/rotate.sh
new file mode 100755 (executable)
index 0000000..f5ca978
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+RM="rm -f"
+MV="mv -f"
+
+if [ $# -ne 2 ]
+then   echo "Usage: $0 <log> <keep>"
+       exit 1
+fi
+
+if [ ! -f "$1" ]
+then   echo "$1 doesn't exist or isn't a file."
+       exit 1
+fi
+
+if [ "$2" -le 0 ]
+then   echo "Keep at least 1 copy please."
+       exit 1
+fi
+
+k="$2"
+$RM "$1.$k" || exit 1
+while [ "$k" -ge 2 ]
+do     prev="`expr $k - 1`"
+       $MV $1.$prev.gz $1.$k.gz 2>/dev/null 
+       k=$prev
+done
+gzip -c $1 >$1.1.gz && : >$1