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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Monitor the age of a file 1

Status
Not open for further replies.

mikevanhoff12

Technical User
Aug 19, 2004
4
0
0
US
I need to monitor the age of a file. If the file is older than 15 minutes, and email should go out. If the file is present, but is under the 15 miute mark, do nothing.

Any help would be greatly appreciated.
 
The find [ /dir/.../dir/targetfile.txt - newer /dir/secondfile.txt ]
will identify the file as newer, but within the 15 minute time period. I have not been able to find switches that will allow this. Any suggestions?
 
I would use perl which has good time functions so in pseudo code. Something along the lines of

Code:
#!/bin/perl -w
use strict;
while (1)
  {
  my ( undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime) = stat ( "file_to_be_tested" );
  my $now = time;
  my $diff = $now - $mtime;
  $dif /= 60; # convert to mins
  if ( $diff > 15 )
     { system "MyMailRoutine" }
  sleep 60;
  }
I'm sure the perl gurus would laugh at my code but I use something similar and it works
 
I don't think it can be done with find. -atime and -mtime are in 24 hour increments (like skulker).
 
maybe u can use istat output?

# istat .profile
Inode 28 on device 10/4 File
Protection: rw-r--r--
Owner: 0(root) Group: 0(system)
Link count: 1 Length 266 bytes

Last updated: Thu Apr 22 10:19:26 2004
Last modified: Thu Apr 22 10:19:26 2004
Last accessed: Tue Aug 24 13:09:42 2004

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top