Generate checksum on directory?

  • Follow


Hi, all.

Anyone know how to generate a checksum on a directory that will change
if any contents of that directory, including subdirectories, changes?

I would like to write a script that monitors activity in a directory
and provide output if there's no activity in a certain amount of time
(~5 min). The best way I can think to do that is with checksums. If
the sum of the parent directory change after 5 minutes, generate the
output.

Thanks in advance.
0
Reply bozothedeathmachine16 (49) 4/27/2011 2:00:29 PM

In comp.unix.solaris bozothedeathmachine <bozothedeathmachine@gmail.com> wrote:
> Anyone know how to generate a checksum on a directory that will change
> if any contents of that directory, including subdirectories, changes?

Easiest thing to do would be to tar the directory into stdout, piped into
sum.  This will catch even little stuff like a timestamp changing.  However,
this isn't a good idea if there's a lot of data in that directory.  Nor does
it tell you what changed, only that a change happened.

cd ${WATCHED_DIR}
NSUM=`tar cf - . | sum`

if [ "${NSUM}" != "${OSUM} ]
then
	send_alert.sh
	OSUM=${NSUM}
fi

Something more efficient would make use of find, iterating down the
tree and summing each file and building a table to compare against.  You
could write such a thing in perl.

-- 
Brandon Hume    - hume -> BOFH.Ca, http://WWW.BOFH.Ca/
0
Reply hume.spamfilter (184) 4/27/2011 2:10:59 PM


bozothedeathmachine <bozothedeathmachine@gmail.com> writes:

>Anyone know how to generate a checksum on a directory that will change
>if any contents of that directory, including subdirectories, changes?

>I would like to write a script that monitors activity in a directory
>and provide output if there's no activity in a certain amount of time
>(~5 min). The best way I can think to do that is with checksums. If
>the sum of the parent directory change after 5 minutes, generate the
>output.

Stat the directory; if it changes, then the stat return will change too.
(If you're interested in changes to the files, then you also need
to stat all the files; the information about those files are not
recorded in the directory)

Casper
-- 
0
Reply Casper.Dik2 (258) 4/27/2011 2:14:10 PM

On Apr 27, 4:10=A0pm, hume.spamfil...@bofh.ca wrote:
> In comp.unix.solaris bozothedeathmachine <bozothedeathmach...@gmail.com> =
wrote:
>
> > Anyone know how to generate a checksum on a directory that will change
> > if any contents of that directory, including subdirectories, changes?
>
> Easiest thing to do would be to tar the directory into stdout, piped into
> sum. =A0This will catch even little stuff like a timestamp changing. =A0H=
owever,
> this isn't a good idea if there's a lot of data in that directory. =A0Nor=
 does
> it tell you what changed, only that a change happened.
>
> cd ${WATCHED_DIR}
> NSUM=3D`tar cf - . | sum`
>
> if [ "${NSUM}" !=3D "${OSUM} ]
> then
> =A0 =A0 =A0 =A0 send_alert.sh
> =A0 =A0 =A0 =A0 OSUM=3D${NSUM}
> fi
>
> Something more efficient would make use of find, iterating down the
> tree and summing each file and building a table to compare against. =A0Yo=
u
> could write such a thing in perl.
>
> --
> Brandon Hume =A0 =A0- hume -> BOFH.Ca,http://WWW.BOFH.Ca/

Thanks, but that really won't work for me. We're looking at a parent
directory with 8TB+ and want to monitor on an interval of ~5 min.

I was also thinking about summing the sums of the files. I'll keep
that in mind.

Thanks
0
Reply bozothedeathmachine16 (49) 4/27/2011 3:45:40 PM

On Apr 27, 4:14=A0pm, Casper H.S. Dik <Casper....@OrSPaMcle.COM> wrote:
> bozothedeathmachine <bozothedeathmach...@gmail.com> writes:
> >Anyone know how to generate a checksum on a directory that will change
> >if any contents of that directory, including subdirectories, changes?
> >I would like to write a script that monitors activity in a directory
> >and provide output if there's no activity in a certain amount of time
> >(~5 min). The best way I can think to do that is with checksums. If
> >the sum of the parent directory change after 5 minutes, generate the
> >output.
>
> Stat the directory; if it changes, then the stat return will change too.
> (If you're interested in changes to the files, then you also need
> to stat all the files; the information about those files are not
> recorded in the directory)
>
> Casper
> --

I checked out the man page. That's a pretty cool function. Is there
anyway to use it as a system call/command though? It seems a bit much
to write a C program just to get the info.

Thanks!
0
Reply bozothedeathmachine16 (49) 4/27/2011 3:48:25 PM

bozothedeathmachine <bozothedeathmachine@gmail.com> writes:

>On Apr 27, 4:14=A0pm, Casper H.S. Dik <Casper....@OrSPaMcle.COM> wrote:
>> bozothedeathmachine <bozothedeathmach...@gmail.com> writes:
>> >Anyone know how to generate a checksum on a directory that will change
>> >if any contents of that directory, including subdirectories, changes?
>> >I would like to write a script that monitors activity in a directory
>> >and provide output if there's no activity in a certain amount of time
>> >(~5 min). The best way I can think to do that is with checksums. If
>> >the sum of the parent directory change after 5 minutes, generate the
>> >output.
>>
>> Stat the directory; if it changes, then the stat return will change too.
>> (If you're interested in changes to the files, then you also need
>> to stat all the files; the information about those files are not
>> recorded in the directory)
>>
>> Casper
>> --

>I checked out the man page. That's a pretty cool function. Is there
>anyway to use it as a system call/command though? It seems a bit much
>to write a C program just to get the info.

Newer versions of Solaris have the "stat" command but what you could do
is something simple like creating a file:

	touch -r /your/directory /tmp/timetamp

(copies the time stamp of your directory to the file /tmp/timestamp)
and then use find to see if it was changed:

	find /your/directory -prune -newer /tmp/timestamp

and either it prints nothing (nothing has changed) or it will print
the name of your directory (something has changed)

When that happens you run the touch command and whetever you want to
do with the directory.

Casper
-- 
0
Reply Casper.Dik2 (258) 4/27/2011 6:22:30 PM

On 4/27/2011 2:22 PM, Casper H.S. Dik wrote:
> bozothedeathmachine <bozothedeathmachine@gmail.com> writes:
> 
>> On Apr 27, 4:14=A0pm, Casper H.S. Dik <Casper....@OrSPaMcle.COM> wrote:
>>> bozothedeathmachine <bozothedeathmach...@gmail.com> writes:
>>>> Anyone know how to generate a checksum on a directory that will change
>>>> if any contents of that directory, including subdirectories, changes?
>>>> I would like to write a script that monitors activity in a directory
>>>> and provide output if there's no activity in a certain amount of time
>>>> (~5 min). The best way I can think to do that is with checksums. If
>>>> the sum of the parent directory change after 5 minutes, generate the
>>>> output.
>>>
>>> Stat the directory; if it changes, then the stat return will change too.
>>> (If you're interested in changes to the files, then you also need
>>> to stat all the files; the information about those files are not
>>> recorded in the directory)
>>>
>>> Casper
>>> --
> 
>> I checked out the man page. That's a pretty cool function. Is there
>> anyway to use it as a system call/command though? It seems a bit much
>> to write a C program just to get the info.
> 
> Newer versions of Solaris have the "stat" command but what you could do
> is something simple like creating a file:
> 
> 	touch -r /your/directory /tmp/timetamp
> 
> (copies the time stamp of your directory to the file /tmp/timestamp)
> and then use find to see if it was changed:
> 
> 	find /your/directory -prune -newer /tmp/timestamp
> 
> and either it prints nothing (nothing has changed) or it will print
> the name of your directory (something has changed)
> 
> When that happens you run the touch command and whetever you want to
> do with the directory.
> 
> Casper

I seem to remember there is something called a "File Alteration Monitor"
(or maybe "file Integrity Monitor") available.  Maybe CSWfam?

-- 
Wayne
0
Reply nospam66 (816) 4/27/2011 6:45:45 PM

On 04/28/11 02:00 AM, bozothedeathmachine wrote:
> Hi, all.
>
> Anyone know how to generate a checksum on a directory that will change
> if any contents of that directory, including subdirectories, changes?
>
> I would like to write a script that monitors activity in a directory
> and provide output if there's no activity in a certain amount of time
> (~5 min). The best way I can think to do that is with checksums. If
> the sum of the parent directory change after 5 minutes, generate the
> output.

If you are running a recent OpenSolaris build (including 11 Express), 
you could uses frequent snapshots and zfs diff.

-- 
Ian Collins
0
Reply ian-news (9881) 4/27/2011 8:09:43 PM

7 Replies
105 Views

(page loaded in 0.345 seconds)

Similiar Articles:













7/25/2012 2:02:52 AM


Reply: