The first thing you should do is add some error checking to your scripts.
add some die() statements at certain points in you script
something like:
WWin32::Service::StopService($name1, $name2) or die "can't stop: $!\n";
also take advantage of
use warnings;
use strict;

try running the script from the command line first to see what is happening
add print statements at certain points to see if the variables you have
there are the way they should be

HTH
Jim


-----Original Message-----
From: Jean-Christophe PINEAU [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 20, 2003 6:07 AM
To: [EMAIL PROTECTED]
Subject: host reboot and Service restart


Hi!
I want to reboot remote hosts and restart remote servers' NT services from
my web server. For the moment it's inside my LAN to make tests (before
putting it in a DMZ). I use the two following scripts. Both are called from
a previous web page with parameters that seem to be correctly filled in. But
the scripts don't work. I mean i can only reboot or restart services on the
localhost where the web server is installed and running, but no other remote
host. The weirdest is that they "sometimes" work when they're run from the
command line!!!!
Any help will be wellcome.

*********reboot.pl***********
# Start the HTML output.  

$name = param('texte');
if ($name eq 'host to reboot'){
 print header;
 print "<HEAD><TITLE>Erreur... Rebootage</TITLE>\n";
 print "<META HTTP-EQUIV=Refresh Content=\"0;URL=entries.pl\">\n";
 print "</HEAD>\n\n<BODY BGCOLOR=#FFFFFF>\n";
 print "<BR><B>entrer un nom d'hôte valide.</B>\n";
 print "</BODY>\n";}

else {  $name = "\\\\" . $name . "\\";
 use Win32;
 Win32::InitiateSystemShutdown($name, "good bye!!", 300, 1, 1);
 print header;
 $out .= "<HEAD><TITLE>Rebootage en cours...</TITLE>\n
 <META HTTP-EQUIV=Refresh Content=\"0;URL=entries.pl\">\n
 </HEAD>\n\n<BODY BGCOLOR=#FFFFFF>\n
 <BR><B>Patientez quelques instants SVP.</B>\n<p>rebootage de ";
 $out .= $name;
 $out .= "</p>\n</body>";
 print $out;
 
 }

***************restart.pl***************
# Start the HTML output.
$name1 = param('hostname');
$name2 = param('service');

if ($name1 eq 'hostname'){
 print header;
 print "<HEAD><TITLE>Erreur... Redémarrage de service</TITLE>\n";
 print "<META HTTP-EQUIV=Refresh Content=\"0;URL=entries.pl\">\n";
 print "</HEAD>\n\n<BODY BGCOLOR=#FFFFFF>\n";
 print "<BR><B>entrer un nom d'hôte valide.</B>\n";
 print "</BODY>\n";}

elsif ($name2 eq 'nom du service tel qu il apparait dans les checks'){
 print header;
 print "<HEAD><TITLE>Erreur... Redémarrage de service</TITLE>\n";
 print "<META HTTP-EQUIV=Refresh Content=\"0;URL=entries.pl\">\n";
 print "</HEAD>\n\n<BODY BGCOLOR=#FFFFFF>\n";
 print "<BR><B>entrer un nom de service valide.</B>\n";
 print "</BODY>\n";}

else { print header;
 $out .= "<HEAD><TITLE>Redémarrage en cours...</TITLE>\n
 <META HTTP-EQUIV=Refresh Content=\"0;URL=entries.pl\">\n
 </HEAD>\n\n<BODY BGCOLOR=#FFFFFF>\n
 <BR><B>Patientez quelques instants SVP.</B>\n<p>redémarrage de ";
 $out .= $name1;$out .= "--";$out .= $name2;
 $out .= "</p>\n</BODY>";
 print $out;
 use Win32::Service;
 WWin32::Service::StopService($name1, $name2);
 $time = time() + 20;
 do {sleep(1);} while ($time > time());
 Win32::Service::StartService($name1, $name2);
 }


_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to