|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 *** |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 *** |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 *** |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
> 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 $? |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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? |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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 ;-) |
|
![]() |
| Outils de la discussion | |
|
|