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

I have a perl script to query the status of my windows server 2012 R2 services. I am unable to get the correct status via running the script. the service status is 'running', but I got 'continue_pending'. I am still trying to figure out if the status I stat in @state_name are correct.
use Win32::Service qw'GetStatus'; use strict; use POSIX; my @state_name = qw( Stopped START_PENDING STOP_PENDING Running CONTINUE_PENDING PAUSE_PENDING PAUSED ERROR ); my $filename = 'D:/log_script/recycle/StartupSvcList.txt'; open FILE, '<', $filename or die "cannot open"; while (<FILE>){ GetStatus("", $servicename, \%status); my $state_no = $status{'CurrentState'}; printf MYFILE " ServiceStatus: %s %s %s \n", "", $servicename, $st +ate_name[$state_no]; } close(MYFILE);

Thanks

Discipulus added a missing closing code tag

Replies are listed 'Best First'.
Re: service status query with wrong status
by poj (Abbot) on Jan 17, 2018 at 16:15 UTC
Re: service status query with wrong status
by thanos1983 (Parson) on Jan 17, 2018 at 15:19 UTC

    Hello ytjPerl,

    If I format your code I see the following:

    You do not open MYFILE and you do not close FILE

    Can you update your code with code tags also? Is this the whole code or something is missing?

    Looking forward to your update, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Re: service status query with wrong status
by karlgoethebier (Abbot) on Jan 19, 2018 at 10:27 UTC

    See also Windows Service Monitoring With Nagios. Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help