Filewatcher

hi All,

I ned to write a filewatcher script, with following requirements.

  1. The script should look for the file in every 5 min.
  2. If the file is found, it should check in every 3 min the size of file.
  3. if the file size has not changed in last 4 iterations (i.e. in last 12 min), the script should exit.
  4. if the file size changes, the script should check in every 3 min untill for last 4 iterations the files size does not change.

I am successfully able to write script which satisfy 1st condition but satisfying 2,3& 4 condition is tricky for me.

All the iteration (i.e. for file check & file size checks)
should be configurable i.e passed as arguments to script.

Appreciate your help!!

Post the script so far.

Here are a couple of clues:

Depending on your OS, you may be able to use the stat command to fetch a file size:

size=$(stat -c %s $filename)

If you don't have stat available you are probably going to have to use cut or awk to strip the size from ls -l $filename output.

You can test the size of integers with -lt like this:

if [ $size -gt $prev_size ] 
then
     echo "File is still growing"
else
     ((same++))
fi
prev_size=$size