Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Reading from a text fileHelpful Member! 

NetNodeMan (TechnicalUser) (OP)
7 Nov 05 6:49
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.
Helpful Member!  tsuji (TechnicalUser)
9 Nov 05 3:38
The text file with multiple-line of ip address with file path x:\abc\def.txt

127.0.0.1
64.233.167.104
216.109.112.135

You read it line by line like this.

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

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.

fspec="x:\abc\pqr.txt"
sh.run commandline & ">" & fspec
NetNodeMan (TechnicalUser) (OP)
9 Nov 05 5:31
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:

Quote:


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...
tsuji (TechnicalUser)
9 Nov 05 5:41
I had a typo up there.
>[/tt]do while not ots.endofstream[/tt]
should be read
do while not ots.atendofstream

As to your new question, since your slog contains some blank space you should do this instead.
>sh.run commandline & ">" & slog
sh.run commandline & ">" & chr(34) & slog & chr(34)

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close