Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file date check

Status
Not open for further replies.
Jun 13, 2002
7
DE
For our database-saves we use flags to check if a save is already running. Lately we had some problems with saves hanging for multiple days without us noticing; we have more than 100 DB to save and monitor.
I was thinking how to check the flags date and couldn't come up with a swift solution. The only thing I came up with was :
Code:
if [ -a /path/file ]
  then 
    check=`find /path -name file -mtime 0 | wc -l`
    if [ $check -lt 1 ]
      then 
         mailx -s 'Save running more than 24 hours' me@work
      fi
    fi
are there better solutions ???

thx in advance ;-)
 
what do you want ??
if /path/file is a file
the find return allways one filename
and the wc allways 1
what is /path/file ??? os ?
vox clamantis in deserto.
 
you might find it useful to look into the 'lsof' [Solaris].

If what you call a 'database-save' is hanging writting to a 'save' file, 'lsof' will list that file as 'open'. vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
well jamisar, just as this forum is named it is a UNIX-korn-shell script on solaris ;-)
to be more precise, with comments now:
Code:
if [ -a /mypath/myflag ]             # does myflag exist
  then                               # if so, check if it was created within the last 24 hours
    check=`find /mypath -name myflag -mtime 0 | wc -l`
    if [ $check -lt 1 ]              # no, it is older then 24 hours
      then                           # so send me a mail-notifier
         mailx -s 'Myflag is set more then 24 hours ago' me@work
      fi                             # yes, flag is created within last 24 hours
    fi                               # no flag exists !!!!
 
no need of comments to read a script.
you my be mean:

(
for DB in list-of-all-db
do
[ -f /path/ctrl$DB ] || {
echo ctrl$DB not found
continue
}
find /path/ctrl$DB -mtime 0 2>/dev/null | grep -c . >/dev/null 2>&1 || continue
echo ctrl$DB older then 24 h.
done
) | mail -s status user

i prefer 'stat()' in 'c' or 'perl'
:)

sure, more code but significant faster as the shell.

#include <stdio.h>
#include <time.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
struct stat query;
long now;
int err = 0;
time(&now);
now -= 86400; /* 24*60*60 */
for(++argv; *argv; ++argv){
if(stat(*argv,&query)){
++err;
printf(&quot;Attention: %s does not exist\n&quot;,*argv);
continue;
}
if(query.st_mtime >now) continue;
++err;
printf(&quot;%s is HANGING\n&quot;,*argv);
}
exit(err);
} vox clamantis in deserto.
 
Thx jamisar,

no offense in me commenting the script, I thought I might have been way to deep into my problem.
The only thing I wanted to know if there is a single UNIX-command to check filedates.

Luckely I can cut & paste and try your solution !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top