INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

Reading from a text file

Reading from a text file

(OP)
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.

RE: Reading from a text file

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

RE: Reading from a text file

(OP)
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...

RE: Reading from a text file

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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

Resources

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