Hi,
I'm a newbie with perl and I don't know much about programming either. I
wrote a script to manipulate services on Windows, and it works fine :
use Win32::Service;
$server_main="\\\\ncedpeuziat";
$server_backup="\\\\nceoatestdp";
$current_date = localtime(time);
open(LOGFILE, ">>CServer_Sync.log");
print LOGFILE "TEST LOG\n\n";
print LOGFILE
"***********************************************************************************\n";
print LOGFILE
"***********************************************************************************\n";
print LOGFILE "\nTEST was started on: ";
print LOGFILE "$current_date\n";
print LOGFILE "Stopping SNMP on $server_backup...\n";
Win32::Service::StopService($server_backup, 'SNMP');
sleep(5);
Win32::Service::GetStatus($server_backup, 'SNMP', \%status);
$Service_Status= $status{CurrentState};
if ($Service_Status == 1) {
print LOGFILE "SNMP service successfully stopped on
$server_backup\n";
} else {
sleep(5);
Win32::Service::GetStatus($server_backup, 'SNMP', \%status);
$Service_Status= $status{CurrentState};
if ($Service_Status != 1) {
print LOGFILE "ERROR: SNMP service cannot be stopped on
$server_backup\n";
close(LOGFILE);
exit;
}
print LOGFILE "SNMP service successfully stopped on $server_backup\n";
}
And I have to do this with a couple of services so I thought I might as
well write a function to do it, and that's where the pb starts:
use Win32::Service;
$server_main="\\\\ncedpeuziat";
$server_backup="\\\\nceoatestdp";
$current_date = localtime(time);
open(LOGFILE, ">>CServer_Sync.log");
print LOGFILE "TEST LOG\n\n";
print LOGFILE
"***********************************************************************************\n";
print LOGFILE
"***********************************************************************************\n";
print LOGFILE "\nTEST was started on: ";
print LOGFILE "$current_date\n";
Stop_Service("SNMP",$server_backup);
sub Stop_Service {
print LOGFILE "Stopping $_[0] on $_[1] ...\n";
Win32::Service::StopService($_[1], '$_[0]');
sleep(5);
Win32::Service::GetStatus($_[1], '$_[0]', \%status);
$Service_Status=$status{CurrentState};
if ($Service_Status == 1) {
print LOGFILE "$_[0] service successfully stopped on $_[1]\n";
} else {
sleep(5);
$Service_Status=Win32::Service::GetStatus($_[1], '$_[0]', \%status);
if ($Service_Status != 1) {
print LOGFILE "ERROR: $_[0] service cannot be stopped on $_[1]\n";
close(LOGFILE);
exit;
}
print LOGFILE "$_[0] service successfully stopped on $_[1]\n";
}
}
I tried to log steps and it seems that the sub cannot interpret the win32
commands....
Any help would be welcome
Thanks
Denis
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs