- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl script not working as expected
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
тАО06-28-2010 12:39 AM
тАО06-28-2010 12:39 AM
I want to check if a file how old is the file. to check this the simple code is as below.
##############################################
#!/usr/bin/perl
$file="/tmp/access_test_log";
my($SECS) = 24*60*60; #seconds in a day
my $ageinsecs = int((-M $file)* $SECS);
print "value of age in secs is $ageinsecs";
##############################################
output is as below:
value of age in secs is 0
Where ls -l /tmp/access_test_log
-rw-r----- 1 root system 0 Jun 21 15:39 /tmp/access_test_log
so if we see actually it is very old file but output say 0. Can some one help me to fix the issue???
KAKA
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2010 01:22 AM
тАО06-28-2010 01:22 AM
Re: Perl script not working as expected
I also get "0" for a non-existing file. You probably have an invisible character somewhere in the file name path.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2010 01:33 AM
тАО06-28-2010 01:33 AM
Re: Perl script not working as expected
Is there other way around to check how old is file???
KAKA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2010 04:59 AM
тАО06-28-2010 04:59 AM
SolutionGeneralize your script and be defensive:
# cat ./myage
#!/usr/bin/perl
use strict;
use warnings;
my $file = shift or die "filename expected\n";
die "'$file' doesn't exist\n" unless -f $file or -d $file;
my $SECS = 24 * 60 * 60; #seconds in a day
my $ageinsecs = int( ( -M $file ) * $SECS );
print "value of age in secs is $ageinsecs\n";
# ./myage "file with spaces in name"
# ./myage myfile
# ./myage /tmp
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-29-2010 12:04 AM
тАО06-29-2010 12:04 AM
Re: Perl script not working as expected
KAKA