Discussion:
Generate checksum on directory?
(too old to reply)
bozothedeathmachine
2011-04-27 14:00:29 UTC
Permalink
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.
h***@bofh.ca
2011-04-27 14:10:59 UTC
Permalink
Post by bozothedeathmachine
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/
Casper H.S. Dik
2011-04-27 14:14:10 UTC
Permalink
Post by bozothedeathmachine
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
--
bozothedeathmachine
2011-04-27 15:48:25 UTC
Permalink
Post by Casper H.S. Dik
Post by bozothedeathmachine
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!
Casper H.S. Dik
2011-04-27 18:22:30 UTC
Permalink
Post by bozothedeathmachine
Post by Casper H.S. Dik
Post by bozothedeathmachine
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
--
Wayne
2011-04-27 18:45:45 UTC
Permalink
Post by Casper H.S. Dik
Post by bozothedeathmachine
Post by Casper H.S. Dik
Post by bozothedeathmachine
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
touch -r /your/directory /tmp/timetamp
(copies the time stamp of your directory to the file /tmp/timestamp)
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
Ian Collins
2011-04-27 20:09:43 UTC
Permalink
Post by bozothedeathmachine
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
Loading...