troubleshooting Question

Service Status

Avatar of Simon336697
Simon336697Flag for Australia asked on
PerlScripting Languages
15 Comments1 Solution2345 ViewsLast Modified:
Hi guys!

I have a script Id like to write that could do the following. -s <servicename> -f <filename>
<servicename> is the name of the service
<filename> is the name of a file that holds a list of computers to process.

What it would do is:

a) Read the filename
b) Connect to each machine
c) Run an sc query \\$system name <$servicename> on each computer in the <filename>
d) Write to the terminal window, and the same standard out, to a file called either running.txt, or stopped.txt, or other.txt, depending on the STATE row of the status, as in the following example;

C:\Documents and Settings\shell>sc query wzcsvc

        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 4  RUNNING
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

So, in the above, output to the terminal would be:

ComputerName             $ServiceName                  $Status
COMPUTER023              wzcsvc                          RUNNING

The above line would also be written to running.txt

So, output to the screen for a list of machines would be:

COMPUTER023              wzcsvc                          RUNNING
COMPUTER023              wzcsvc                          STOPPED
COMPUTER912              wzcsvc                          RUNNING
COMPUTER41                wzcsvc                          PAUSED

The stopped entries go to stopped.txt.
The running entries go to running.txt
Anything else, goes to other.txt

Any help appreciated.
Join our community to see this answer!
Unlock 1 Answer and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros