CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Execute subroutine at given time each day (within program not with cron)

 



Innovate1
New User

Oct 15, 2014, 11:05 AM

Post #1 of 2 (5384 views)
Execute subroutine at given time each day (within program not with cron) Can't Post

I have a script checking some things and reporting (via email) if it finds errors. That is run with cron multiple times a day. Once a day (say 8 AM local time) I want it to report status regardless of errors or not to make sure it is running. I have the basic script to report errors. Now I need to add the once per day condition and want this to be part of the same script.


BillKSmith
Veteran

Oct 15, 2014, 1:08 PM

Post #2 of 2 (5381 views)
Re: [Innovate1] Execute subroutine at given time each day (within program not with cron) [In reply to] Can't Post

I have a similar problem. I have a task which must be done during my first login each day. My solution is to run the script at every login and exit without doing useful work if it is not the first login. I keep the time of the previous login in a file.


Code
open my $PREV_LOGIN, "<", "$prev_login_file"; 
my $prev_login_day = <$PREV_LOGIN>;
close $PREV_LOGIN;

my @loc_time = localtime;
my ($wday, $yday) = @loc_time[6,7];

exit 0 if $prev_login_day == $yday and !$test_mode;

open $PREV_LOGIN, ">", "$prev_login_file";
print {$PREV_LOGIN} $yday;
close $PREV_LOGIN;

# Do task here.


You should be able to adapt this method to your application.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives