The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with perl and if file statement Dadwith2boys Shell Programming and Scripting 1 09-01-2009 06:33 PM
case statement in UNIX scripting (ksh) luna_soleil UNIX for Dummies Questions & Answers 4 03-03-2009 02:05 AM
Problem with if statement in perl kamitsin Shell Programming and Scripting 2 10-04-2008 01:19 PM
Perl equivalent of ksh if / echo statement gefa Shell Programming and Scripting 2 02-17-2005 12:07 PM
perl if statement Bashar Shell Programming and Scripting 3 12-25-2004 06:12 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
nettech207 nettech207 is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 2
help with if statement perl scripting

Sorry for the newbie question

I need to create a perl script to check the modifed time of a file I already have that part created but need help in creating a if statement that basicly will check to see if the modifed time is at least 2hrs older then the current time if the stament is true to send out a email

here is what I have
the print statement are mainly just for debugging purpose
Code:
#!/usr/bin/perl
use strict;
use warnings;
use POSIX;
# To get time
my $currDate = time;
my $thisFile = "/usr/local/ahps2/tmp/****";
my $mtime  = (stat($thisFile))[9];
print "1: $mtime \n";
my @lt = localtime($mtime);
# The get file info
my $ptime = strftime ("%R",@lt);
print "2: $ptime \n";
print "3: $currDate \n";
print "\n";
print $currDate . "\n";

Last edited by pludi; 2 Weeks Ago at 02:31 AM.. Reason: code tags, please...
  #2 (permalink)  
Old 2 Weeks Ago
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 517
Quote:
Originally Posted by nettech207 View Post
...
if statement that basicly will check to see if the modifed time is at least 2hrs older then the current time if the stament is true to send out a email
...
Since "time" returns the number of non-leap seconds since whatever time your system considers to be The Epoch, you simply need to check that the difference between current time and the file's mtime is at least 7200.

Here's one way to do it:

Code:
$
$ cat -n cmpmtime.pl
     1  #!/usr/bin/perl -w
     2  $file = $ARGV[0];
     3  if (time - (stat($file))[9] >= 7200) {
     4    print "The file $file is at least 2 hours old.\n";
     5  } else {
     6    print "The file $file is less than 2 hours old.\n";
     7  }
     8
$
$ # I have a file already (tstfile) that is more than 2 hours old
$
$ perl cmpmtime.pl tstfile
The file tstfile is at least 2 hours old.
$
$ # And I shall create a file right now
$ touch newfile
$
$ perl cmpmtime.pl newfile
The file newfile is less than 2 hours old.
$
$
HTH,
tyler_durden
  #3 (permalink)  
Old 2 Weeks Ago
nettech207 nettech207 is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 2
thanks durden that helps alot now to figure oout how to sendmail if statement is true

thanks again
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0