Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Modify Current Script for Querying Services.

Posted on 2013-01-21
7
Medium Priority
?
320 Views
Last Modified: 2013-01-21
Hi All,

I have a script that allows me to check if my backup services are running on multiple servers that have been rebooted after patching the OS, it also pings the server as well, the script runs fine in the dos window and i can see the results as they happen but for some reason the script will not output those results to a csv/excel file.

What i would like on the headers of the output file are the following.

Computer name - Ping - Service Name - Running - Stopped

Heres the script i have.

@echo off
setlocal enabledelayedexpansion
Set ServerFile=c:\Servers.txt
set ServiceList="BackupExecRPCService","BackupExecAgentAccelerator","BackupExecJobEngine","BackupExecDeviceMediaService","BackupExecAgentBrowser"
set CsvDelim=,
set CsvFile=%~dpn0.csv
set Header="Computer"
for %%a in (%ServiceList%) do (set Header=!Header!!CsvDelim!"%%~a")
>%CsvFile% echo !Header!
for /f "usebackq tokens=1" %%a in ("%ServerFile%") do (
      set Line="%%~a"
      echo Processing %%a ...
      ping.exe -4 %%a | find /i "TTL" >NUL
      if errorlevel 1 (
            echo ... not responding.
            for %%a in (%ServiceList%) do (set Line=!Line!!CsvDelim!"NO_PING")
      ) else (
            echo ... responding, querying services ...
            for %%s in (%ServiceList%) do (
                  set State=NOT_FOUND
                  for /f "tokens=2,3 delims=: " %%u in ('sc.exe \\%%~a query "%%~s" 2^>NUL ^| find "STATE"') do (set State=%%~v)
                  set Line=!Line!!CsvDelim!"!State!"
                  echo ... %%~s: !State!
            )
      )
      >>%CsvFile% echo !Line!
)
output.JPG
0
Comment
Question by:Alan OBrien
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 38800800
What is the name of your script? If it contains spaces, try renaming the script by removing the spaces from it. Do you get any output file btw?
0
 
LVL 4

Author Comment

by:Alan OBrien
ID: 38800920
name of the script is checkservices.bat but it wont output to the csv, it will give me output on the command line(see attached jpg) which does give the correct results but no csv
0
 
LVL 85

Expert Comment

by:oBdA
ID: 38800930
The script should create a file <Scriptname without extension>.csv in the script's folder; if it doesn't, check if the account you're using has permissions to delete/create this csv file:
C:\Temp>test.cmd
Processing LOCALHOST ...
... responding, querying services ...
... Spooler: STOPPED
... DHCP: RUNNING
Processing FOO ...
... not responding.

C:\Temp>type test.csv
"Computer","Spooler","DHCP"
"LOCALHOST","STOPPED","RUNNING"
"FOO","NO_PING","NO_PING"

Open in new window

0
Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

 
LVL 4

Author Comment

by:Alan OBrien
ID: 38800983
Hi

I have other scripts in the folder that can generate csv files, i run the script as administrator and i am setup on the machine as administrator so not sure what i am missing?
thanks.
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 38800998
Please copy just that script and servers.txt into a new test folder and run it again from an elevated command prompt.
When the script is done, there should be a new file "checkservices.csv" containing the information.
0
 
LVL 4

Author Comment

by:Alan OBrien
ID: 38801087
For some reason the above worked even though i had ran the script from an elevated account, don't understand why it does but it does as other scripts ran fine in the folder. thanks for the help guys.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 38801373
strange, I ran first part of the script and got an output file just fine, without elevation...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question