#!/bin/bash
# This script periodically checks the size of a specified
# log file. If the file size exceeds a specified maximum, then
# the log is moved to a backup location.

# This is the logfile to check
logfile=/var/log/syslog

# This is where to move the log
backupLogfile=/mnt/hda/syslog.bak

# Move logfile when size exceeds maxsize bytes
maxsize=50000 

# Sleep this many seconds between checking the file size
sleeptime=600

# Keep track of how many times file has been moved
nMoves=0

while [ 1 ]
do

  let filesize=`ls -l $logfile | sed -f /etc/siam/fs.sed`

  if [ "$filesize" -gt "$maxsize" ] 
  then 
    ### echo "$logfile file size exceeds $maxsize - need to make move it"
    mv $logfile $backupLogfile
    let nMoves="$nMoves+1"
    echo "New file number $nMoves started at " `date` > $logfile
  fi

  sleep $sleeptime

done
