- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help on file time stamp monitoring
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 07:52 AM
тАО03-22-2010 07:52 AM
I have a file in which i need to monitor whether the file is updating in timely manner. Can someone help me in designing a script to send an alert (using mailx) if the file is not updated for last 5 minutes?
Thanks,
Ramkumar A.
Solved! Go to Solution.
- Tags:
- scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 09:44 AM
тАО03-22-2010 09:44 AM
SolutionYou could do something like this:
# cat ./monitor
#!/usr/bin/perl
my $secs = shift or die;
my $file = shift or die;
while (1) {
die "Missing file '$file'\n" unless -f $file;
if ( ((stat($file))[9]) < (time() - $secs) ) {
system qq( mailx -s "File Alert" < /dev/null yourname@\@your.com > /dev/null );
}
sleep(5); #...adjust as desired...
}
1;
...run as:
# ./monitor seconds filename
...as to monitor a file for update every 600 seconds:
# ./monitor 600 /path_to_file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 10:14 AM
тАО03-22-2010 10:14 AM
Re: Help on file time stamp monitoring
access time / atime
ls -u
Use time of last access
modification time / mtime
ls -c
Use time of last modification of the inode (file created, mode changed, etc.) for sorting (-t) or printing (-l (ell)).
initialization -or- create time / ctime
ls -c
Also see 'stat' command
# stat filename
time_t st_atime; /* Time of last access */
time_t st_mtime; /* Last modification time */
time_t st_ctime; /* Last file status change time */
http://docs.hp.com/en/B2355-90693/stat.2.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 10:42 AM
тАО03-22-2010 10:42 AM
Re: Help on file time stamp monitoring
Thanks for the script. I ran the script against the old file(/tmp/ramtest1.txt) like below and its not returning to command prompt and i didnt get the email too.
shcscp19# ./monitor 600 /tmp/ramtest1.txt
Please advise.
Thanks,
Ramkumar A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 10:47 AM
тАО03-22-2010 10:47 AM
Re: Help on file time stamp monitoring
The line:
# system qq( mailx -s "File Alert" < /dev/null yourname@\@your.com > /dev/null );
...should have been:
# system qq( mailx -s "File Alert" < /dev/null yourname\@your.com > /dev/null );
Change the string "yourname\@your.com" to the address you want.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 10:54 AM
тАО03-22-2010 10:54 AM
Re: Help on file time stamp monitoring
It was already present like you specified and my email address was updated. But still after running the script, its not returning to command prompt and no emails triggered.
shcscp19# cat monitor
#!/usr/bin/perl
my $secs = shift or die;
my $file = shift or die;
while (1) {
die "Missing file '$file'\n" unless -f $file;
if ( ((stat($file))[9]) < (time() - $secs) ) {
system qq( mailx -s "File Alert" < /dev/null ranantharam3@csc.com > /dev/null );
}
sleep(5);
}
1;
shcscp19# ./monitor 600 /tmp/ramtest1.txt
Please advise.
Thanks,
Ramkumar A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 11:09 AM
тАО03-22-2010 11:09 AM
Re: Help on file time stamp monitoring
> But still after running the script, its not returning to command prompt and no emails triggered.
As I wrote the script, it runs until interrupted (with a Control_C). If the file represented by the second argument passed is older than the number of seconds specified by the first argument, then an email alert is generated. The assumption is the the file is constantly being updated.
If you want to script to test and exit, change it to:
# cat ./monitor
#!/usr/bin/perl
my $secs = shift or die;
my $file = shift or die;
die "Missing file '$file'\n" unless -f $file;
if ( ((stat($file))[9]) < (time() - $secs) ) {
system qq( mailx -s "File Alert" < /dev/null jim-ferguson\@smh.com > /dev/null );
}
1;
...run as before. To check is the file hasn't been updated in 5-minutes (600 seconds):
# ./monitor 600 file
This queries the 'mtime' of the 'stat()' structure which has a value in Epoch seconds.
Regards!
...JRF...