PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Monitor A Directory for Changes
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Monitor A Directory for Changes

Réponse
 
LinkBack Outils de la discussion
Vieux 23/08/2006, 18h32   #1
Borf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Monitor A Directory for Changes

I want to create a cron job that looks at a directory and sends me an
email if a new file (or any changes) have been made since the last time
I checked.
Does anyone know of a way to do this?

Thanks,
Borf

  Réponse avec citation
Vieux 23/08/2006, 19h42   #2
Stachu 'Dozzie' K.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Monitor A Directory for Changes

On 23.08.2006, Borf <anthony@station5.net> wrote:
> I want to create a cron job that looks at a directory and sends me an
> email if a new file (or any changes) have been made since the last time
> I checked.
> Does anyone know of a way to do this?


And what kind of problem do you have with this task?

--
<Kosma> Niektórzy lubi± dozziego...
<Kosma> Oczywi¶cie szanujemy ich.
Stanislaw Klekot
  Réponse avec citation
Vieux 23/08/2006, 21h54   #3
Borf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Monitor A Directory for Changes

No problem, I just don't know how to do this and I am looking for .
I am running ksh on a HP Unix.

Stachu 'Dozzie' K. wrote:
> On 23.08.2006, Borf <anthony@station5.net> wrote:
> > I want to create a cron job that looks at a directory and sends me an
> > email if a new file (or any changes) have been made since the last time
> > I checked.
> > Does anyone know of a way to do this?

>
> And what kind of problem do you have with this task?
>
> --
> <Kosma> Niektórzy lubi± dozziego...
> <Kosma> Oczywi¶cie szanujemy ich.
> Stanislaw Klekot


  Réponse avec citation
Vieux 23/08/2006, 21h57   #4
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Monitor A Directory for Changes

In article <1156366453.600127.192660@i3g2000cwc.googlegroups. com>,
"Borf" <anthony@station5.net> wrote:

> No problem, I just don't know how to do this and I am looking for .
> I am running ksh on a HP Unix.


List the directory and save the result to a file. List it again and
compare the new list with the old one. If there's a difference, send an
email.


> Stachu 'Dozzie' K. wrote:
> > On 23.08.2006, Borf <anthony@station5.net> wrote:
> > > I want to create a cron job that looks at a directory and sends me an
> > > email if a new file (or any changes) have been made since the last time
> > > I checked.
> > > Does anyone know of a way to do this?

> >
> > And what kind of problem do you have with this task?
> >
> > --
> > <Kosma> Niektórzy lubi± dozziego...
> > <Kosma> Oczywi¶cie szanujemy ich.
> > Stanislaw Klekot


--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Vieux 25/08/2006, 14h55   #5
Borf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Monitor A Directory for Changes

Have you done this before? Do you have a sample script?

Is there a way to check the directory to see the last time anything in
it was changed?
does the directory maintain a timestamp?


Barry Margolin wrote:
> In article <1156366453.600127.192660@i3g2000cwc.googlegroups. com>,
> "Borf" <anthony@station5.net> wrote:
>
> > No problem, I just don't know how to do this and I am looking for .
> > I am running ksh on a HP Unix.

>
> List the directory and save the result to a file. List it again and
> compare the new list with the old one. If there's a difference, send an
> email.
>
>
> > Stachu 'Dozzie' K. wrote:
> > > On 23.08.2006, Borf <anthony@station5.net> wrote:
> > > > I want to create a cron job that looks at a directory and sends me an
> > > > email if a new file (or any changes) have been made since the last time
> > > > I checked.
> > > > Does anyone know of a way to do this?
> > >
> > > And what kind of problem do you have with this task?
> > >
> > > --
> > > <Kosma> Niektórzy lubi± dozziego...
> > > <Kosma> Oczywi¶cie szanujemy ich.
> > > Stanislaw Klekot

>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***


  Réponse avec citation
Vieux 26/08/2006, 03h04   #6
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Monitor A Directory for Changes

In article <1156514104.138609.324670@i42g2000cwa.googlegroups .com>,
"Borf" <anthony@station5.net> wrote:

> Have you done this before? Do you have a sample script?


No I haven't. I figure the script should take a good scripter under an
hour, maybe a bit longer for someone less experienced.

Use: ls -l directory > filename

to save the contents of the directory to a file. And

cmp -s filename prevfilename

to compare the file just created with the previous one.

>
> Is there a way to check the directory to see the last time anything in
> it was changed?
> does the directory maintain a timestamp?


The directory has a modification time, but that will only be updated
when files are added, removed, or renamed. It won't tell you if a file
within the directory was modified in place.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Vieux 26/08/2006, 18h47   #7
Jon LaBadie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Monitor A Directory for Changes


> Stachu 'Dozzie' K. wrote:
>> On 23.08.2006, Borf <anthony@station5.net> wrote:
>>> I want to create a cron job that looks at a directory and sends me an
>>> email if a new file (or any changes) have been made since the last time
>>> I checked.
>>> Does anyone know of a way to do this?

>> And what kind of problem do you have with this task?
>>

Borf wrote:
> No problem, I just don't know how to do this and I am looking for .
> I am running ksh on a HP Unix.



A possibility is to use find to compare one files timestamp against those
of the files in the directory. Note, this will not detect deleted files
and unless your find supports -cnewer and -newer, it will not detect files
with changed permissions or ownership.

One sample not tested:

$ cat dirck
#!/bin/ksh

ProgName=${0##*/}

# Directory to check
DirToCk="$1"
[[ $DirToCk == /* && -d $DirToCk ]] || {
echo "Usage: $ProgName <full path to directory to ck>" >&2
exit 1
}


# place to store timestamp files
LastCkDir=/usr/local/lib/$ProgName
[[ -d $LastCkDir ]] || mkdir $LastCkDir || {
echo "$ProgName: Time Stamp directory, '$LastCkDir' does not exist and could not be created" >&2
exit 1
}

# time stamp file (replace pathname /'s with _'s)

# if HP's ksh supports substitution use this line, else use tr line
#_Dir_To_Ck_=${DirToCk//\//_}
_Dir_To_Ck_=$(echo $DirToCk | tr / _ )
TimeStampFile=$LastCkDir/$_Dir_To_Ck_
[[ -f $TimeStampFile ]] || {
echo "ProgName: First Check of $DirToCk, can only create timestamp file" >&2
touch $TimeStampFile && exit 99
echo "$ProgName: could not create timestamp file '$TimeStampFile'" >&2
exit 1
}

# HP's find may not have -cnewer, -newer can be substituted
# but will not detect permission or ownership changes

# may wish to add "-maxdepth 1" if desired and supported by HP find
# may wish to add "-type f" to limit checking to ordinary files
ExtraOpts="-maxdepth 1 -type f"

find $DirToCk ${ExtraOpts} -cnewer $TimeStampFile -ls

touch $TimeStampFile
exit $?
  Réponse avec citation
Vieux 27/08/2006, 05h42   #8
Michael Paoli
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Monitor A Directory for Changes

Store the ctime of the directory. If the ctime happens to be the
current time, wait at least one second, and try again, repeating as
necessary until one obtains a ctime from the directory that is not
the current time. When one wants to compare in the future, check the
ctime. If it hasn't changed, then the *directory* hasn't changed
(and file(s) haven't been added to the directory). Note that
strictly speaking this will satisfy the specified requirement of
detecting changes to the directory - but that may not be precisely
what is desired/intended. E.g. changing a file in a directory is not
the same as changing the directory.

This also doesn't cover filesystems that are not of a "UNIX" type,
bypassing security or system integrity, etc.

Borf wrote:
> I want to create a cron job that looks at a directory and sends me an
> email if a new file (or any changes) have been made since the last time
> I checked.
> Does anyone know of a way to do this?


  Réponse avec citation
Vieux 27/08/2006, 16h58   #9
Loki Harfagr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Monitor A Directory for Changes

Le Sat, 26 Aug 2006 21:42:55 -0700, Michael Paoli a écrit:
> Borf wrote:
>> I want to create a cron job that looks at a directory and sends me an
>> email if a new file (or any changes) have been made since the last time
>> I checked.
>> Does anyone know of a way to do this?


> Store the ctime of the directory. If the ctime happens to be the
> current time, wait at least one second, and try again, repeating as
> necessary until one obtains a ctime from the directory that is not
> the current time. When one wants to compare in the future, check the
> ctime. If it hasn't changed, then the *directory* hasn't changed
> (and file(s) haven't been added to the directory). Note that
> strictly speaking this will satisfy the specified requirement of
> detecting changes to the directory - but that may not be precisely
> what is desired/intended. E.g. changing a file in a directory is not
> the same as changing the directory.
>
> This also doesn't cover filesystems that are not of a "UNIX" type,
> bypassing security or system integrity, etc.


For this side problem you would store not only the ctime but also
some "crossproofs" like sh1sum md5sum, 'du -s' of the dirs and so on,
as we don't know much about the env which the OP wants to survey
not much more can be said yet :-)

Though, if it is for a desktop simple control the script would
be almost trivial but, if it is for a real world survey on systems
there are certainly better choices in many IDS tools than to reinvent
an heptagonal wheel in seven lines of script ;-)
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h08.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17322 seconds with 17 queries