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

Reading from a text file 1

Status
Not open for further replies.

NetNodeMan

Technical User
Mar 30, 2005
65
IE
I have a script that will telnet to a switch and do a sh run on the switch. This works fine for one switch.

However, I need to run this for over 200 switches now and as I am a networks guy and not a scripter, I need a bit of help.

Can someone help me to read in an IP address and then read the sh run output to a text file? I'm completely useless at this (Im not a scripter) so if there's code available could someone post it if that's ok?

Thanks in advance.
 
The text file with multiple-line of ip address with file path x:\abc\def.txt
[tt]
127.0.0.1
64.233.167.104
216.109.112.135
[/tt]
You read it line by line like this.
[tt]
fspec="x:\abc\def.txt"
set fso=createobject("scripting.filesystemobject")
set ots=fso.opentextfile(fspec)
do while not ots.endofstream
s=ots.readline 'this is your ip address 127.0.0.1 for instance
'do thing with the info s
loop
ots.close
set ots=nothing
set fso=nothing
[/tt]
You must prepare the text file as such no empty lines etc. I said this just because you demonstrate some lack of skill to elaborate the demo.

To redirect the output to a text file, append the part to the line you are working with.
[tt]
fspec="x:\abc\pqr.txt"
sh.run commandline [blue]& ">" & fspec[/blue]
[/tt]
 
Brilliant tjusi.

I can now read in the lines one by one - however, it will get to the last IP address and keep telnetting to this i.e. looping.


Also, I am creating a dynamic file as below:

slog = "c:\log\" & s & " " & Right("0" & Day(Date), 2) & Right("0" & Month(Date), 2) & Year(Date) & ".log"


set logfile=fso.opentextfile(slog,8,true)


wscript.echo now()
sh.run commandline & ">" & slog
Is this how I should be redirecting the output or have I missed something? The log isn't creating...
 
I had a typo up there.
>[/tt]do while not ots.endofstream[/tt]
should be read
[tt]do while not ots.[red]at[/red]endofstream[/tt]

As to your new question, since your slog contains some blank space you should do this instead.
>[tt]sh.run commandline & ">" & slog[/tt]
[tt]sh.run commandline & ">" [blue]& chr(34)[/blue] & slog [blue]& chr(34)[/blue][/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top