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.

#!/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:

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.

If you can install the CPAN module Date::Calc, then your goal could be accomplished like so -

$
$
$ 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

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

#!<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:

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

tyler_durden