Script for Log Rotate

Hello,
I only know the basic for shell programing. I need help for this, I thinks this is a basic for anyone who know a litle of shell scripting.

I need creat a script for a rotatate logs, when a filesystem is full. I have a filesystem.

The rotate consist in zip the current log (copy) and trucate the file in use (> file.log).

I do:

#!/usr/bin/ksh
eadonly FILESYSTEM=$1
export FILESYSTEM
DIA=`date  +%D %H:%M`
FECHA=`date '+%d/%m/%y %H:%M:%S'`
export DIA FECHA
touch /home/{$USER}/liberar.filesystem.PID
echo $$ >> /home/{$USER}/liberar.filesystem.PID
touch /home/{$USER}/log.liberar.filesystem.{$DIA}.log
cd $FILESYSTEM
echo ESTADO FILESYSTEM $FILESYSTEM >> /home/{$USER}/log.liberar.filesystem.{$DIA}.log
df -k . | tee >> /home/{$USER}/log.liberar.filesystem.{$DIA}.log
echo LISTADO DE FICHEROS ORDENADOS POR PESO $FILESYSTEM >> /home/{$USER}/log.liberar.filesystem.{$DIA}.log
du -k . | sort -n

I would like use the order list, (du -k . | sort -n) to do:

  1. Copy in tmp directory.
  2. compress file in tmp directory
  3. truncate original file
  4. move compress file from tmp directory to original path.

All of them task for all logs in the list...

How I can do it?

Thanks!!!

El Rengo

man logrotate :wink: