Log Rotate Example

a simple script for log rotation, used in systems without logrotate.

#!/bin/sh

# Assignments
script=$1
num_of_rotates=$2

# Rotation
i=$num_of_rotates
while [ $i -gt 1 ]
do
   minus=`expr $i - 1`
   if [ ! -f $script.$minus ]
   then
touch $script.$minus
   fi
   mv $script.$minus $script.$i
   if [ "$minus" -eq 1 ]
   then
cp -fp $script $script.1
cp /dev/null $script
   fi
        let "i -= 1"
done

Related Posts

  • No related post found

Published by

avishay

avishay

HTMLy user