monitor size of file in realtime

How would one monitor the size of a file in realtime, then when it reaches a certain size (like 10megs), gzip, append timestamp to filename and scp to another box?

regards

Use sleep command, and ls -l or du command within a loop until the file size reaches your upper limit, and then add the timestamp and transfer.

Please try out and post if you have further problems.

My first attempt...

Check file size
If file reached file size
Append date to filename
Compress filename.$date
scp filename.$date to target server

#!/bin/bash
SIZE=`ls -la syslog.log | cut -d' ' -f 5 `
echo $SIZE

if [ "$SIZE" -ge 10000000 ]
  then
    `mv syslog.log syslog.log.$date | gzip syslog.log.$date | scp syslog.gz jdoe@system.com:\home\jdoe\logs `
  else
    echo "size not reached yet"
sleep 5
fi

Do you know, in general, what is the purpose behind using backticks (`) and using pipe(|)?

get rid of those backquote and pipe

 
mv syslog.log syslog.log.$date 
gzip syslog.log.$date 
scp syslog.gz jdoe@system.com:\home\jdoe\logs
/or/
mv syslog.log syslog.log.$date  && mv syslog.log syslog.log.$date && 
scp syslog.gz jdoe@system.com:\home\jdoe\logs

Good attempt! You haven't used any loop structure. You can try using while or until loop.

I think Vidyad meant that last line to be
mv syslog.log syslog.log.$date && gzip syslog.log.$date &&
scp syslog.gz jdoe@system.com:\home\jdoe\logs

But I'm not sure about that $date variable- does that work? I think in the shell I've been using I had to use `date` command instead.

hope this will solve your doubt :smiley:

 
fnsonlu1-/home/fnsonlu1> date=`date`
fnsonlu1-/home/fnsonlu1> echo $date
Tue Mar 17 12:25:51 IST 2009
fnsonlu1-/home/fnsonlu1>date="vidya"
fnsonlu1-/home/fnsonlu1> echo $date
vidya
fnsonlu1-/home/fnsonlu1>