Compress all INACTIVE Files

Hi gurus,

I have a batch job running daily night automatically. The job produces file with extension '.0' like a.0, b.0 etc.

Now due to file space constraints, most of the time, the job fails with insufficient disk space and then we have to manually start the job again and keep running the gzip/compress command on all the *.0 files (to compress them and make way for more files) which are not used by the backup job.

Now can you please help me in creating the shell script for this.

All I want my script to do this -

  1. Fuser .0 one by one.
  2. If the file is active then proceed with next .0 file.
  3. If the file is not active (I mean if fuser does not report any process locking the file) then run the compress in background.

Pls. help
Thanks

cd /path/to/files
for filename in `ls -1 *.0`
do
	echo "`fuser $filename`" | grep -q "$filename"
	if [ $? -ne 0 ]; then
	   compress $filename
	fi
done