Operating System - HP-UX
1753969 Members
7229 Online
108811 Solutions
New Discussion юеВ

Script to check for file size change on list of files over 2 minutes

 
SOLVED
Go to solution
Paul D. Simpson
Frequent Advisor

Script to check for file size change on list of files over 2 minutes

Hi All,

I'm looking for a shell script fragment to test files named in an inventory file to see if their size changed minute to minute over a 2 minute timeframe. Script will run from cron every 15 minutes. Basically moving oracle audit files that are done writing to a remote server. Not sure how oracle generates audit logs, but if possible, I'd also be open to checking to see if file was done writing & then moving.

eg:
1st run: creates inventory.txt with file size & name using:
ls -lrt ${AUDITDIR}|awk '{print $5,$9}'>inventory.txt

sleeps 60 sec

<>
for each file listed in inventory.txt, check to see if filesize changed. If no, delete from inventory.txt, append filename into movefiles.txt.

sleep 60 again

for each file listed in inventory.txt, check to see if filesize changed. If no, delete from inventory.txt, copy filename into movefiles.txt.

delete inventory.txt.

<< at this point I'll create md5 checksums for all files in movefiles.txt and copy the checksum files & files listed to a remote server with scp. >>

5 REPLIES 5
Laurent Menase
Honored Contributor

Re: Script to check for file size change on list of files over 2 minutes

a simple idea

while :
do
ls -lrt ${AUDITDIR}|awk '{print $5,$9}'>inventory2.txt

diff inventory* | grep ">"
if [ $? -eq 1 ]
then
break
fi
mv inventory2.txt inventory.txt
sleep 60
done
Dennis Handly
Acclaimed Contributor
Solution

Re: Script to check for file size change on list of files over 2 minutes

Perhaps something like:

if [ ! -r inventory.txt ]; then
ll -rt ${AUDITDIR} | awk 'NF >= 9 {print $5,$9}' > inventory.txt
fi

for counter in 1 2; do
sleep 60
> inventory2.txt
while read size file; do
new_size=$(ll $AUDITDIR/$file | awk '{print $5}')
if [ $new_size -eq $size ]; then
echo $file >> movefiles.txt
else
echo $file >> inventory2.txt # save
fi
done < inventory.txt
mv inventory2.txt inventory.txt
done

rm -f inventory.txt
Laurent Menase
Honored Contributor

Re: Script to check for file size change on list of files over 2 minutes

Just 1 odif
ls -l ${AUDITDIR}|sort| awk '{print $9,$5}'>inventory2.txt

while :
do
ls -l ${AUDITDIR}|sort |awk '{print $9,$5}'>inventory2.txt

diff inventory* | grep ">"
if [ $? -eq 1 ]
then
break
fi
mv inventory2.txt inventory.txt
sleep 60
done
Sen Hu
New Member

Re: Script to check for file size change on list of files over 2 minutes

You can use the following script in biterscripting (http://www.biterscripting.com) . Save the old output and compare with the new one periodically.

# Get file list from inventory file.
var str fileList
cat inventory_file >$fileList
while ($fileList <> "")
do
# Get next file.
var str file
lex "1" $fileList >$file
accessfile $file

# The new size is now in system variable $fsize. Compare.

done

Should work in all windows versions.

Sen
James R. Ferguson
Acclaimed Contributor

Re: Script to check for file size change on list of files over 2 minutes

Hi:

@ Sen : Should work in all windows versions.

This forum is for HP-UX (UNIX) discussions. There is a separate Microsoft forum here:

http://forums11.itrc.hp.com/service/forums/familyhome.do?familyId=116

Regards!

...JRF...