Perl script that checks against Future time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl script that checks against Future time
# 1  
Old 06-16-2010
Perl script that checks against Future time

Ok, so this may be an unusual request. But I have a certificate that expires sometime in may of 2011. Now, i have to monitor this certificate and alert when the current time is within 30 days of may 20, 2011.


Code:
#!/usr/bin/perl
#
use Time::Local;
#
$sec=59;
$min=59;
$hours=23;
$day=31;
$month=11;
$year=109;
#
$current = time();
print "Current (epoch) time: $current\n";
#
$newyear = timegm($sec,$min,$hours,$day,$month,$year);
print "New Year's Eve 2009: $newyear\n";
#
print "Only " .($newyear-$current) . " seconds to go\n";

The above script gives the following output:

Code:
Current (epoch) time: 1234911622
New Year's Eve 2009: 1262303999
Only 27392377 seconds to go

While this output isn't exactly what I want, I figured some of you here may be able to modify the script that produces it to help me accomplish what I need done.

I want this script to be able to output the amount of days, hours, or minutes, before a certain date, in this case, May 20, 2011.

Thanks guys.
# 2  
Old 06-16-2010
If you can install the CPAN module Date::Calc, then your goal could be accomplished like so -

Code:
$
$
$ perl -M"Date::Calc" -e '@x=localtime();
                          @y=Date::Calc::N_Delta_YMDHMS($x[5]+1900,$x[4]+1,$x[3],$x[2],$x[1],$x[0],2011,5,20,0,0,0);
                          printf("%d years, %d months, %d days, %d hours, %d minutes, %d seconds remaining till 20-May-2011 12:00:00 AM.\n", @y)'
0 years, 11 months, 3 days, 10 hours, 25 minutes, 58 seconds remaining till 20-May-2011 12:00:00 AM.
$
$

tyler_durden

Last edited by durden_tyler; 06-16-2010 at 02:46 PM..
# 3  
Old 06-18-2010
thank you so much for your post. one quick question though, how do I put this into a script? like in the format of the script I posted in the first post.

thanks
# 4  
Old 06-18-2010
Quote:
Originally Posted by SkySmart
... how do I put this into a script? like in the format of the script I posted in the first post.
...
Code:
#!<path_to_perl_on_your_system> -w
use Date::Calc qw(N_Delta_YMDHMS);
@x = localtime();
@y = N_Delta_YMDHMS($x[5]+1900,$x[4]+1,$x[3],$x[2],$x[1],$x[0],2011,5,20,0,0,0);
printf("%d years, %d months, %d days, %d hours, %d minutes, %d seconds remaining till 20-May-2011 12:00:00 AM.\n", @y);

Replace the string <path_to_perl_on_your_system> with the actual path to perl on your system.

And Date::Calc module must be installed in your system for this script to work. Otherwise you'd see the standard error message:

Code:
Can't locate Date/Calc.pm in @INC (@INC contains: ... ... ...

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Time out set in perl script

Hi, I am preparing a perl script, which will run some commads on remote Linux servers. I have a file contains all the servers names one by one like below vi servers.txt srv1 srv2 srv3 Now, I need to prepare a perl script to ssh (or)rsh to each server in the above... (1 Reply)
Discussion started by: kumar85shiv
1 Replies

2. Shell Programming and Scripting

Script to do the following checks

Hi , I need a script for processing below scenario. I have to check daily by doing ftp IP to check it is logging or not. So i want this activity to be automated such that if login succesful i will get "FTP LOGIN SUCCESS" in a log file and if fails i want the error message in the same log... (1 Reply)
Discussion started by: sv0081493
1 Replies

3. Shell Programming and Scripting

Script to performs checks

Hi , I need a script which performs below activity I have one file named "testfile" in 9 different directories with same name. I want to perform below action with each testfile of each directory. if ; then mv listfiles listfiles_`date +%b%y` else echo No Such files fi ... (4 Replies)
Discussion started by: sv0081493
4 Replies

4. UNIX for Dummies Questions & Answers

Delete Unix/Linux file at a specific time in future.

Hi, I was wondering if there is a command to delete a file in the future. For example: If I create a file named unix.lst using the vi editor, but after I create it, what command will be suitable to delete "unix" files from the system at 13:40 military time with no log file. I was going to... (3 Replies)
Discussion started by: abhi7514
3 Replies

5. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

6. UNIX for Dummies Questions & Answers

ls -ltr for a future date/time stamp file

Hi When i do ls -ltr <file1> then it shows me the date and time of the file if - for whatever reason file has future date/time stamp then ls -ltr is not showing the time, it just shows only date part ... even if time is ahead by 2 hr than current time. suppose a file was copied from INDIA... (3 Replies)
Discussion started by: reldb
3 Replies

7. Shell Programming and Scripting

need shell or Perl script to get the epoch time automatically

I need shell or Perl script to get the epoch time automatically Example I need to execute mysql command to delete content less then given epoch time If date is 01-07-2010 (dd-mm-yy) epoch should be lees 7 days mean 23-06-2010 for 23-06-2010 I need epoch time Delete BS_table where... (1 Reply)
Discussion started by: sreedhargouda
1 Replies

8. Programming

Date time problem while executing perl script.

Hi All, This Monday 15th March 2010, i have faced a weired issue with my Perl script execution, this script is scheduled to run at 1 minute past midnight on daily basis ( 00:01 EST ) generally for fetching previous business date , say if it is Monday it should give last Friday date, for Tuesday... (0 Replies)
Discussion started by: ravimishra
0 Replies

9. Shell Programming and Scripting

time stamp perl script error out of range 1..31

Hi, while running the perl script i am getting this error message , Day '' out of range 1..31 at rsty.sh line 44 what do iam missing in the script, any suggestion #!/usr/bin/perl use Time::Local; my $wday = $ARGV; my $month = $ARGV; # convert the month shortname into 0-11 number if... (4 Replies)
Discussion started by: saha
4 Replies

10. Shell Programming and Scripting

perform some checks on file using perl

hi i want check for PVCS header in file if its present then check if its in proper format or not i want to do this is in perl on windows. this is what i am doing : 1 . open file 2 . check for "PVCS information" if found then store the line no to $line var. 3 . check for "sccs" header ... (0 Replies)
Discussion started by: zedex
0 Replies
Login or Register to Ask a Question