Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

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  

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

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  
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

This is probably too late for you but should be useful for anyone else looking for something similar, as I was recently...

You are not specifying the correct information in your command line. Also The systeminfo command only has a boot time, not an uptime. That would create an empty file.

systeminfo /s Server1 /u %login%  /p %pwd%   | find "System Boot Time"  >> c:\Uptime\A.txt

You can use cut from unixutils to cleanup the file more.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .