Portree has asked for the wisdom of the Perl Monks concerning the following question:

Hello All,
I have done some research on this and I need to see if I can get some more information. I have a program that checking a second computer to see if it still online. If the second computer is not online then I need it to run a perl script on a server. What is the best way to do this? I have posted my code below, but not sure if that will help.

The Sub "Late File" is where I would want to kick off the script. I have idenfitied the second script as $backup_report and that is what I would like to have run. Any assistance is greatly appreciated.

Portree
use strict; use warnings; use win32::ole; use Date::Calc; use Mime::Lite; my @modify; my $modify_seconds; my $sleep_count = 0; my $final_time; my $a_final_denis = '//10./Automated Reports/Final_Denis_Test.pl'; my $backup_report = '//163./planning/Logistics/Programs/Chicago WIP Qu +ery Tools/Final_Denis_Test.pl'; &checkfile ($a_final_denis); sub checkfile { my $file = shift(@_); my $flag = 1; my $sleep_count = 0; while ($flag){ if (-e $file) { @modify = stat ($file); $modify_seconds = $modify[8]; print "$file\n"; if (&checktime ($modify_seconds, $file)) { $flag = 0; } else { $sleep_count++; if ($sleep_count > 3) {&late_file} sleep(3); } } else { print "File not found\n"; goto F_End; } } } sub checktime { my $modify_seconds = shift(@_); my $file = shift(@_); my $local_time = localtime($modify_seconds); my $current_tm = time(); $final_time = $current_tm - $modify_seconds; print "$final_time\n"; if ($final_time >= 80000) { return 0; }else { goto Q_End; } } sub late_file { open $backup_report; print "File Is Late In Updating"; exit 1; } ########################################### F_End: open $backup_report; my $msg_end = MIME::Lite->new( From =>'rzcj60@freescale.com', #who is sending the email To =>'rzcj60@freescale.com', # who is receiving the email Subject =>'Final Denis Report Innactive', # subject of the ema +il Type =>'multipart/mixed' #what type of email (it is like t +his since it is text and attachment) ); $msg_end->attach(Type =>'TEXT/Plain', #what is being atta +ched Data =>"Computer running Final_Denis automated re +port is not active" #The body of the email ); MIME::Lite->send('smtp', "freescale.net", Timeout=>60); #smtp r +outing information for email $msg_end->send; # send function exit; Q_End: print "File Updated"; exit;

Replies are listed 'Best First'.
Re: Backticks and Sub Programs
by ikegami (Patriarch) on Sep 08, 2005 at 20:08 UTC

    I see some problems unrelated to your question at a glance.

    1) What's open $backup_report;? That just dies in 5.6.1 and 5.8.0. Update: oh I see, this is a placeholder.

    2) use win32::ole; should be use Win32::OLE;. The former will load the module, but won't import any symbols because package names are case-sensitive.

    3) You shouldn't use & in front of function names unless you know how it affects the function being called. No, it's not purely decorative.

    4) I think putting a space in front of a function's opening parenthesis can confuse perl in some circumstances. I'm not sure what those are.

    5) It's wierd to exit from a successful function. You should move the goto Q_End; to the line after &checkfile ($a_final_denis);

Re: Backticks and Sub Programs
by 5mi11er (Deacon) on Sep 08, 2005 at 19:28 UTC
    Check out this recent post that goes over the various ways to run another perl script. From my reading of that thread, the 'do' function sounded like the way to go.

    HTH,

    -Scott

Re: Backticks and Sub Programs
by ambrus (Abbot) on Sep 09, 2005 at 09:52 UTC

    To check if the other computer is online, the best way depends on that computer and your connection to it (you meaning the machine running the script). If you want to ensure that some service (like a webserver) is running on the other computer, it's probably best to check that service directly, not just whether the computer is alive. If you still just want to check for the computer to be alive, the best is probably to use the ping program. If the machine doesn't answer pings, use nmap -sP -PA and possible give it port numbers too.