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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Ping

Status
Not open for further replies.

NetNodeMan

Technical User
Mar 30, 2005
65
IE
I have the following code which I want to use to ping a number of servers:

Dim Shell, PingExec, PingOutput,Wshshell, SystemPath, Result, Server

SystemPath="C:\winnt\system32"
'set shell = server.createobject("wscript.shell")

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\srvinfo\test.txt", ForReading, True)
server = objTextFile.ReadLine

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
oShell.Run "command /C ping.exe " & Server & "> Ping.txt"

Wscript.echo Result
Wscript.Echo server
objTextFile.close


Wscript.Quit

What I actually want to do is to run a srvinfo rather than a ping. The result of this srvinfo would then be written to a file which would be updated each day i.e. the log file would have a daily timestamp on it. I have this working for one server and it writes to Ping.txt but how do I do this for multiple servers and multiple outputs?

Thanks in advance.
 
How would I do a srvinfo in the above instance instead of a ping?
 
>How would I do a srvinfo in the above instance instead of a ping?
Not much different, I guess.
>[tt]oShell.Run "command /C ping.exe " & Server & "> Ping.txt"[/tt]
[tt]oShell.Run "command /C svrinfo -d -r -s -v \\" & Server & "> svrinfo.txt"[/tt]
 
That just continually opens a cmd shell saying "Bad command or filename"
Dim Shell, PingExec, PingOutput,Wshshell, SystemPath, Result, Server

SystemPath="C:\winnt\system32"
'set shell = server.createobject("wscript.shell")

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\srvinfo\test.txt", ForReading, True)
server = objTextFile.ReadLine

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
oShell.Run "command /C srvinfo -d -r -s -v \\" & server & "> srvinfo.txt"


Wscript.echo Result
Wscript.echo server
objTextFile.close


Wscript.Quit
 
What do you know about svrinfo.exe. Can you share it first with us? Do you have it on your m/c? Supply the command line with its exact path.
 
srvinfo:

c:\winnt\system32

The srvinfo syntax seems to be correct (the one you gave me) but now the cmd shell won't close. It looks like it's running forever.
 
Try a variation of it?
[tt]oShell.Run "%comspec% /C c:\winnt\system32\srvinfo -d -r -s -v \\" & server & " > srvinfo.txt"[/tt]
 
Cheers. But Im not getting output on my cmd shell. Is my code ok?
 
>But Im not getting output on my cmd shell. Is my code ok?
Please be definite. Do the cmd window close? Else we don't know what is the progress if any!
 
I have output but the cmd doesn't close. Also, I have 4 servers in my .txt file but it only reads one.
 
but it only reads one
So, reread my post dated 20 Sep 05 4:13

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You read one line, so you have one server's data. What else to expect? But that part can be done later, looping and " >>" instead of ">". Main thing is to get the functionality right.
 
Replace /C by /k and leave out the redirection, see what is one the screen.
[tt]oShell.Run "%comspec% /C c:\winnt\system32\srvinfo -d -r -s -v \\" & server[/tt]
 
I meant.
[tt]oShell.Run "%comspec% /k c:\winnt\system32\srvinfo -d -r -s -v \\" & server[/tt]
 
tsuji,

Thanks for your help. As ever you've been courteous and helpful.

PHV,
Many people who use this place haven't the first idea about scripting. Obviously some others are well educated in scripting, such as tjusi and yourself. However, that doesn't give you a divine right to be snotty with newbies like myself. I genuinely hope you never have to ask someone for help and they turn to you and say "Read the fucking manual" Then again, I genuinely do hope that happens. Thanks for being so welcoming to anyone whose expertise in the field wasn't as prficient as your own.

I thought the reason places like this existed was to help guys like me but obviously you feel it's to feed the ego of guys like you.
 
Not that i want to stick my oar in but,

PHV tends to post alot of

'have a look at the manual'

In PHV's defense i would say the following.
I am a vbscript legend. I have 2 shortcuts on my desktop one is WSH help files and the other is Vbscript help files from MS. I open and ref these manuals on a daily basis (i am afraid to say). So, if you are a scripting novice or a scripting legend i would say PHV's post is a valid one.

Mores the point, I hear i forget, I see i remember, I do I understand. If you ever want to learn vbscript then i suggest you take PHV's advice and start reading the manual then you will start to actually LEARN something.

People dont contribute to forums because they want to provide answers to peoples questions, its more a case of helping someone learn something, this is where he joy is.
Whilst i am guilty of posting fully working code to someones question (usually cause i am a sucker for stars) it is much more rewarding when you feel someone has actually learnt something and a light has been turned on.

With direct reference to this thread I see nothing that is 'snotty' in them. If PHV's posts come across that way then I think you are mistaken and you will find it is a direct result of people mis-using this forum when they try and get a quick script which will save them from actually using their grey matter.

von moyla
 
Von Moyla,

I can completely understand where he's coming from and where you're coming from. I'm a moron when it comes to scripting but hear me out. I'm not looking for a large piece of code to be written for me. I do run a very thorough search for every question I post but being a novice at this means that I see code but don't fully understand it. I do appreciate that guys like me need to use a bit more grey matter (and I genuinely would LOVE to be able to script, it's so handy) but if a learner driver needs to learn how to drive you don't hand them a manual do you? I would be quite happy with an answer such as:

Declare variablers
<syntax>
See this link for ping/srvinfo
<syntax>
Exit

A link to the contents of some online book isn't very helpful. I'd rather my post ignored than to be treated sanctimoniously. I don't mean to be picky but that's my point. Maybe there's a link to a beginner's forum that might be more handy that passing me the manual.

P.S. I didn't come on to have a go at anyone but I didn't come here to be patronised either. Most people have been extremely helpful to be honest
 
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\srvinfo\test.txt", ForReading, True)
Set oShell = CreateObject("WScript.Shell")
While Not objTextFile.AtEndOfStream
server = objTextFile.ReadLine
WScript.Echo server
oShell.Run "your srvinfo call here >> srvinfo.txt"
WEnd
objTextFile.close
Wscript.Quit


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top