The manual steps are controled by a small script like
Code:
#!/bin/sh
FILENAME="/your/location/your-file"
if [ -f "$FILENAME".4.gz ]; then
rm -f "$FILENAME".4.gz
fi
if [ -f "$FILENAME".3.gz ]; then
mv -f "$FILENAME".3.gz "$FILENAME".4.gz
fi
if [ -f "$FILENAME".2.gz ]; then
mv -f "$FILENAME".2.gz "$FILENAME".3.gz
fi
if [ -f "$FILENAME".1.gz ]; then
mv -f "$FILENAME".1.gz "$FILENAME".2.gz
fi
if [ -f "$FILENAME" ]; then
gzip -c "$FILENAME" > "$FILENAME".1.gz
echo -n "" > "$FILENAME"
fi
But for a more simple way as I said, let logrotate handle it, create a file in /etc/logrotate.d with a section like:
Code:
/your/location/your-file {
rotate 4 # create upto .4.gz
compress # gzip compresses the file
missingok # its OK if it's not there
monthly # could be weekly or daily
notifempty # if file is empty dont rotate it
}
You can look at logrotate(8) for more info on which settings to give it.
Bookmarks