Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm not familiar with scripting. I have a task at hand which requires to check server uptimes to make sure if they were actually re-booted when they suppose to.

I was going through Google Search and have found an idea of an input.txt file, which contains all server names and output.txt, which contains the result.

The issue is that each server has a unique general login. e.g login name is domain\server1, password is server1domain. My input file is like:

domain\server1, server1domain
domain\server2, server2domain
domain\sevrer3, server3domain

I would like to use serverinfo /s | find "uptime" >>c:\output.txt, and output.txt I would like to be:

domain\server1      uptime   <uptime of server>
domain\server2      uptime   <uptime of server>
domain\server3      uptime   <uptime of server>

and so on until end of input.txt file.

Could someone create a very basic batch file?

share|improve this question
2  
Hi Ben! First, welcome to Super User! Please check out your formatting when you post. There's a preview window to show you how your question will look like. You need to check our formatting help. Could you maybe edit your question and show us what you already have and where specifically you're stuck? Don't forget to indent code by 4 spaces (or select it and press Ctrl-K). –  slhck Feb 7 '13 at 20:50
add comment

1 Answer

I have made some changes, hope it would help. What I have at this time is a batch file which I tried to modify as per my environment:

I have an input.txt containing a list of my server names, where this loop is picking up server names line after line. At the same time I am trying to have unique login credentials within the script, this way I will not have to manually enter login credentials for them. Here is my script. The problem I am facing is that the login credentials are not getting passed as values when systeminfo.exe is executing.

for /f "delims=" %%a in (c:\Uptime\Input.txt) do (  
    echo %%a  
    set x=yellow  
    set login=%x%%%a  
    set pwd=%%a%x%  
    echo %login% pwd %pwd%  
    systeminfo /s %%a /u %login% /p %pwd% | find "System Up Time" >> c:\Uptime\A.txt  
    pause  
)  

When I execute this batch file, I get the following:

C:\Uptime>(  
echo Server1  
 set x=yellow  
 set login=Server1 <- it should be: yellowServer1  
 set pwd=Server1  <- it should be: Server1yellow  
 echo  pwd <- not showing the values of variables from above, should be: yellowServer1 Server1yellow  
 systeminfo /s Server1 /u  /p    | find "System Up Time"  1>>c:\Uptime\A.txt  
 pause  
)  
Server1  
 pwd  
ERROR: Invalid Syntax. Value expected for '/u'.  
Type "SYSTEMINFO /?" for usage.  
Press any key to continue . . .  

I am not sure why it is not taking the values from the variables in the systeminfo cmd line.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.