dcsimg
Results 1 to 4 of 4

Thread: Redirecting output to a text file

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    2

    Redirecting output to a text file

    Hello Experts,

    I am using below vb script to telnet to a switch and run some commands. But I dont know how to redirect the output of the commands to a text file. I need the output of the commands "show" and "config" send to a text file. Any help is greatly appriciated.

    Code:
    Dim objShell
    Dim objNetwork

    Set objNetwork=CreateObject("WScript.Network")

    strTitle="Telnet Demo"
    strDefaultServer="Server01"
    strDefaultUser=objNetwork.UserDomain & "\" & objNetwork.UserName
    strDefaultPassword="P@ssw0rd"

    strComputer=InputBox("What server or device do you want to connect to?",_
    strTitle,strDefaultServer)
    If Len(strComputer)=0 Then WScript.quit

    strUsername=InputBox("What credential do you want to use",strTitle,_
    strDefaultUser)
    If Len (strUsername)=0 Then WScript.Quit

    strPassword=InputBox("What password do you want to use?",strTitle,_
    strDefaultPassword)
    If Len (strPassword)=0 Then WScript.Quit

    Set objShell=CreateObject("wscript.shell")
    'Start Telnet
    objShell.Run "Telnet " & strComputer
    'Give app a chance to get started
    WScript.Sleep 5000
    objShell.AppActivate "Telnet " & strComputer

    'Send login credentials
    objShell.SendKeys strUsername & "~"
    WScript.Sleep 2000
    objShell.SendKeys strPassword & "~"
    WScript.Sleep 2000

    'Send commands
    objShell.SendKeys "show"
    WScript.Sleep 200
    objShell.SendKeys "~"
    WScript.Sleep 200
    objShell.SendKeys "config"
    WScript.Sleep 200
    objShell.SendKeys "~"

    'Close session
    'make sure we get window again
    objShell.AppActivate "Telnet " & strComputer
    objShell.SendKeys "logout"
    WScript.Sleep 200
    objShell.SendKeys "~"

    Thanks in advance

  2. #2
    Junior Member
    Join Date
    May 2008
    Posts
    22

    Re: Redirecting output to a text file

    Hi,

    I would really like to help with this, but I have exactly the same problem. I just need to confirm if exchange server is running and a telnet command will do that but I can't capture the output from the Telnet. I'll keep track of your post. Good luck.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,148

    Re: Redirecting output to a text file

    I'd suggest you try something else.

    Go to Dimac Free Downloads and get w3sockets.

    This is a scriptable ActiveX component that can do Telnet as well as simple TCP client connections. No more troublesome SendKeys or Sleep calls.

    You can send commands directly and get the output directly. If you want to you can write any received output to disk via the FSO of course.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,148

    Re: Redirecting output to a text file

    Oh, you can find the reference material at w3Sockets Reference.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width