View Single Post
  #14  
Old 10-14-2008, 05:11 AM
nxg nxg is offline
Registered User
 
Join Date: Sep 2008
Posts: 8
Hi,

You'll be glad to know I fixed it! As I've seen a lot of 'it's fixed' replies in the forum without people actually saying what they've done (which can be really frustrating to newbies with the same problem), I'll post what was wrong.

1. My sessionlist.txt file had ';' delimited site name and IP in it, which is where the 'PS' was coming from. The txt file now just has an IP in it.

2. The cnxnString was wrong. The correct one is in the working script below.

This now connects to the IP address, sends the 'dir' command then disconnects. Not very useful in itself but is the proof of concept I needed to sequentially send multiple commands to multiple devices, while automatically accepting SSH keys if required.

Thanks for your help, and I hope this comes in useful for other 'newbies'.

#$language = "VBScript"
#$interface = "1.0"

Sub Main

Const username = "xxxxx" ' Username to use for login
Const password = "xxxxx" ' Password for corresponding user

Const DEVICE_FILE_PATH = "C:\Program Files\SecureCRT\Scripts\sessionlist.txt"

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fil
Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)

Dim ip
Dim cnxnString

'On Error Resume Next

While Not fil.AtEndOfStream

ip = fil.ReadLine

cnxnString = "/SSH2 /L " & username & " /PASSWORD " & password & " /C 3DES /M MD5 " & ip & " /AcceptHostKeys"

' Connect

crt.Screen.Synchronous = True

crt.Session.Connect cnxnString

crt.Screen.WaitForString "#"

crt.Screen.Send "dir " & vbCr

crt.Screen.WaitForString "#"

crt.Screen.Synchronous = False

crt.Session.Disconnect

Wend

fil.Close

End Sub
Reply With Quote