Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows 2003 Server - CMD file syntax

Status
Not open for further replies.

alfie002

Technical User
Mar 3, 2004
121
GB
Dear all,

Before I post a question I want to make sure that I am posting in the right forum. My question is syntax related to cmd files that are running on a Windows 2003 server. Can someone confirm if this is the right forum, alternatively suggest another one as I haven't spotted one devoted to windows CMD file scripting.

Thanks

Alf
 
depends what the question is alfie! Ask away, if its in the wrong place I'm sure some nice person will point out which is the best forum :)
 
Hello Hondy, Ok thanks for that. Essentially what I need to do os created a CMD script to read through a list of servers and these these server redirecting the output (the standard output and the standard error output to a log file)

I have created the following. Running through loop if fine, pinging the servers is fine, the problem is that there is no output in the logfile.

Any ideas would be welcomed.

Thanks

Alf


@echo on
REM *****************************************************************************************************************
REM * Title: A "cmd" file to read server list file and then ping and log the results.
REM * Date 30.07.2008
REM * REM *****************************************************************************************************************
set log_file=c:\temp\telnet_result.log
set server_list=c:\temp\server_list.txt
set timer=date/t
echo Start: Read server list file from %server_list%. > %log_file%
time /t >> %log_file%
for /L %%A IN (1,1,1) do for /F %%I IN ('type %server_list%') do telnet %%I %%A >>%log_file% 2>&1
echo Error Level = %errorlevel%
time /t >> %log_file%







 
This might not be entirely what you're after, and it's a little more long winded than yours.

This script (save it as 'whatever.vbs' if you like) must be held in the same location as the list of the machines you want to ping (I called it CompList.txt).

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strHost
Const ForReading = 1

Set objCompFile = objFSO.OpenTextFile("CompList.txt",ForReading)
Set objSuccessLog = objFSO.OpenTextFile("SuccessLog.txt",2,True)
Set objFailureLog = objFSO.OpenTextFile("FailureLog.txt",2,True)

Do Until objCompFile.AtEndOfStream
			strHost = objCompFile.ReadLine
				If Ping(strHost) = True then
					objSuccessLog.Writeline strHost & " pinged successfully." & vbCRLF
				else
					objFailureLog.Writeline strHost & " did not ping successfully" & vbCRLF
				End if
			'objCompFile.MoveNext
	Loop
	objCompFile.Close
    objSuccessLog.Close
    objFailureLog.Close
	Wscript.Echo "Script execution complete."
	Wscript.quit
    
    	Function Ping(strHost)
		dim objPing, objRetStatus
		Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
		 ("select * from Win32_PingStatus where address = '" & strHost & "'")
		 for each objRetStatus in objPing
			if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
				Ping = False
			else
				Ping = True
			end if
		next
	End Function

Hope that helps.

(Apologies to the code-gestapo that will probably reel in utter horror at the state of the script - I had to modify one of my other scripts to make it).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top