- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Check time
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
Forums
Discussions
Discussions
Discussions
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
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
05-27-2002 05:31 AM
05-27-2002 05:31 AM
I???ve a problem,
With this command: ls ???ltr events/e*/* |awk ???NR==1 [print $8]???
I find the oldest file in a directory.
This file is removed from time to time,
And I need to know if It is becoming is older than 20 minutes
I can compare time stamp with current date(date command)
But I don???t know thow to create script to understand
If this file is older than 20 minutes.
Regards, Angelo
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 05:52 AM
05-27-2002 05:52 AM
Re: Check time
all you need is a reference file which you need to compare with your found file.
man touch
touch reference_time filename
With this command you make a file with a reference time. Use this file with find command to check the age.
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 06:16 AM
05-27-2002 06:16 AM
Re: Check time
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x1ac191ccb36bd611abdb0090277a778c,00.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 06:20 AM
05-27-2002 06:20 AM
Re: Check time
Well, you can get the similar date from from date '+%H:%m'. Try splitting the hour and minute and using expr to figure out if the difference is less than 20.
Cheers,
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 06:20 AM
05-27-2002 06:20 AM
Re: Check time
Using your command:-
#!/bin/sh
# File Watcher
# Log file /tmp/fwatcher
fdate=`ls ???ltr events/e*/* |awk ???NR==1 [print $8]???`
date >>/tmp/fwatcher
echo $fdate >>/tmp/fwatcher
mailx -s "File Watcher log" (Your email address)
Cron it to run when you require and monitor the log file.
Quick, easy and mailed to your desktop.
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 07:11 AM
05-27-2002 07:11 AM
Re: Check time
------------------------------------------
#!/usr/contrib/bin/perl
$now = time;
foreach $filename (@ARGV) {
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat $filename;
$age = ($now - $mtime) / 60 ;
if ( $age > 20 ) {
printf ("WARNING: %s is %d minutes old\n", $filename, $age);
}
}
---------------------------------------
All you do is run the script, with the file(s) you want the age of as parameters
eg: how_old.sh
Where
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2002 08:29 AM
05-27-2002 08:29 AM
SolutionCheck if you've also got /opt/perl/bin/perl, which should be version 5.6.1
--8<---
#!/opt/perl/bin/perl -w
use strict;
my $now = time;
foreach my $filename (@ARGV) {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat $filename;
$age = ($now - $mtime) / 60 ;
if ($age > 20) {
print "WARNING: $filename is $age minutes old\n";
}
}
-->8---
how_old.sh would be a very misleading name for a perl script. Please us .pl as extension, so others will still know what to expect.
eg: how_old.pl
There have been many more threads that look like this one, and the perl solution could be made much more flexible if you use the standard module File::Find.
The age of a file can also (and much easier) be determined with the -M and -A operators (age of the file since the start of the script measured in (fractions of) days
-M $file > 4 and die;