#1
|
|||
|
|||
Run commands on list of IPs
Hi,
I've been looking through examples and the responses to some other user's questions but being VBS blind haven't been able to get anything working. I need to run 5 commands on each of 250 devices. I'd like to put the commands in the script and have the devices sourced from a text file that contains the list of IP addresses. I need to connect by SSH2, accept the key if required and enter a username and password, then run a series of commands. It would be nice but not essential to log the results. Another option with the device/command combo is to have the IP address and command on the same line, comma (or other) delimited. Any help much appreciated! |
#2
|
|||
|
|||
Hi nxg,
Could you post your script as you have it so far? Along with your script, could you provide details as to where/how the script is failing? Also, although you may have already reviewed this example script, I have attached an example which demonstrates the process of reading login information from a file. Is this example script helpful? |
#3
|
|||
|
|||
Thanks for the quick reply. I tried altering a script I found on the forum to do what I required but it failed at the first line (not including the VBS and ver statement) when it couldn't find the file! I had to give up as like I said, I have no idea about VBS.
Are there any examples available that show reading from a txt file list, logging in over SSH2, sending a command etc? |
#4
|
|||
|
|||
Hi nxg,
We do not have an example script that accomplishes exactly what it is you are looking to do. Since you found an example that does what you require, perhaps I can provide information about that script to help you modify the script to fit your needs. Can you post the script that demonstrates what it is you are are trying to accomplish? |
#5
|
|||
|
|||
I get a Connection Failed at line 32 message appear after a moment, though it does open a window... The sessionlist.txt file just contains one IP address on the first line at the moment.
#$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\VanDyke Software\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 & 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 Last edited by nxg; 10-10-2008 at 10:52 AM. |
#6
|
|||
|
|||
Hi nxg,
Is the connection failed dialog indicating the correct IP address? Also, can you verify that you can connect to this IP address manually from SecureCRT? This test can be performed by select 'Quick Connect' from the SecureCRT 'File' menu, entering the IP address and clicking the 'Connect' button. |
#7
|
|||
|
|||
The tab says "PS; 10.250.86.11" which is the correct IP address. I can connect to this host fine using Quick Connect (with the same credentials).
The error says: CRT Scripting Runtime Error Error: Connection Failed File: [PATH]\test2.vbs Line: 32 Line 32 is: crt.Session.Connect cnxnString and cnxnString is defined as: cnxnString = "/SSH2 /L " & username & " /PASSWORD " & password & ip & " /AcceptHostKeys" ![]() Last edited by nxg; 10-13-2008 at 08:52 AM. |
#8
|
|||
|
|||
Hi nxg,
I have not been able to reproduce the behavior you have described. Could you enable Trace Options output in the default session, run the script again, and send me the entire output of the connection attempt? Steps to enable Trace Options output in the default session are below: 1. Browse to the SecureCRT Config folder |
#9
|
|||
|
|||
Hi,
I tried that, but don't get any output. |
#10
|
|||
|
|||
Hi nxg,
I am curious about the 'PS;' characters that you reported as showing up in the tab caption. Can you add the following line after you execute the ip=fil.ReadLine method, run your script again, and send me the results of the MsgBox? Code:
MsgBox "IP address is: " & ip |
#11
|
|||
|
|||
I added it as shown below, but it still fails at the same place and doesn't popup a message box.
ip = fil.ReadLine MsgBox "IP address is: " & ip cnxnString = "/SSH2 /L & /AcceptHostKeys " & username & " /PASSWORD " & password & ip ' Connect crt.Screen.Synchronous = True '31 crt.Session.Connect cnxnString crt.Screen.WaitForString "#" |
#12
|
|||
|
|||
Hi nxg,
It seems strange that the script is not displaying the MsgBox but is making it to the connection call. Can you verify that the MsgBox line was added and saved into your script? Also, can you post your complete modified script, and provide the exact error message you are seeing? Last edited by jdev; 10-13-2008 at 02:26 PM. |
#13
|
|||
|
|||
OK, here's the script (username and password obscured, but have been checked as correct). I've re-installed the program from scratch, having cleared out all files and registry entries from the previous install. A screenshot of the error message is attached.
#$language = "VBScript" #$interface = "1.0" Sub Main Const username = "xxxxxx" ' Username to use for login Const password = "xxxxxx" ' Password for corresponding user Const DEVICE_FILE_PATH = "C:\Program Files\SecureCRT\Scripts\sessionlist.txt" '10 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 MsgBox "IP address is: " & ip cnxnString = "/SSH2 /L & /AcceptHostKeys " & username & " /PASSWORD " & password & ip ' Connect crt.Screen.Synchronous = True ' 31 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 |
#14
|
|||
|
|||
Hi,
You'll be glad to know I fixed it! ![]() 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 |
#15
|
|||
|
|||
Hi nxg,
I am glad to hear the issue is resolved. Thanks for posting the resolution. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|