1847172 Members
6639 Online
110263 Solutions
New Discussion

Re: script

 
SOLVED
Go to solution
Luc Monnens
Frequent Advisor

script

Hey all,

I am looking for a script or command to find out if any of the files in a given directory have been changed/modified/deleted/added (since the previous run).
All help is appreciated.
Thank you.

Kind regards,

Luc Monnens
5 REPLIES 5
Peter Nikitka
Honored Contributor

Re: script

Hi,

I suggest to collect a checksum of all directory entires and compare these results:
chkdir=my/direc/tory
cd chkdir
ls -a | xargs cksum | sort >/tmp/base${chkdir##*/}.cksum

For later comparisions:
...
ls -a | xargs cksum | sort >/tmp/new${chkdir##*/}.cksum

comm -3 /tmp/base${chkdir##*/}.cksum /tmp/new${chkdir##*/}.cksum

Look at the man pages of 'cksum' and 'comm' for further information. The analysis of the output of the comm command is left as an exercise ....

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
MarkSyder
Honored Contributor

Re: script

Today:

cd /directory
ll -tr > /tmp/inventory.18042007

tomorrow:

cd /directory
ll -tr > /tmp/inventory.19042007
diff /tmp/inventory.18042007 /tmp/inventory.19042007

NB - there is no line break in the diff command - it merely shows that way in this box.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Hein van den Heuvel
Honored Contributor

Re: script

The simple approach is to leave a file behind when the run is done: # touch last-run.
Next to find changed files just use find:
# find ${RUNDIR} -newer last-run

This might not be good enough as it could find files for which the date was change but the data not. And it might not find files for which the contents was changed, but the date reset to fall before the last-run.

I consider both a good feature for most production environments.

But for 'secure' environments you may prefer a checksum mechanism as outlined before as it is 99.99% certain to catch file content modifications.

fwiw,
Hein.

john korterman
Honored Contributor
Solution

Re: script

Hi Luc,

try running the attached script, specifying the complete path to the dir to check as $1.

regards,
John K.


it would be nice if you always got a second chance
Luc Monnens
Frequent Advisor

Re: script

John's script gave me exactly what I was looking for so he got the 10.
Because of that the others were not really valued on their merrits.
Thank you all for your input.
Much appreciated.

Kind regards,

Luc