Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #16  
Old 10-28-2008, 10:20 AM
Myo Myo is offline
Registered User
 
Join Date: Oct 2008
Posts: 1
Hi nxg,

Thanks for your script.

Myo
Reply With Quote
  #17  
Old 11-17-2008, 01:11 AM
sfcavin sfcavin is offline
Registered User
 
Join Date: Nov 2008
Posts: 4
secureCRT Version 4.1.10 (build 292)

Anyone know why this version of CRT would crash after running the script listed in this post? The script works great, but when it's done secureCRT throws the general Windows error "This program has encountered an error and needs to close....." then I get this error "VNotificationSink: SecureCRT.exe Application Error" basically a "memory could not be read" error. I've attached the script just as it is when I run it save for changing the username and pass.

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

Sub Main

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

Const DEVICE_FILE_PATH = "C:\script\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

' 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
  #18  
Old 11-17-2008, 10:39 AM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi sfcavin,

Since SecureCRT 4.1 is such an older version it is hard to tell the exact reason the application could be crashing.

In my testing, the last maintenance release of SecureCRT 4.1 (4.1.11) is not crashing when running the script you provided.

SecureCRT 4.1.11 can be downloaded here.

Does the crash still occur in your environment after upgrading to SecureCRT 4.1.11?
Reply With Quote
  #19  
Old 11-17-2008, 02:18 PM
sfcavin sfcavin is offline
Registered User
 
Join Date: Nov 2008
Posts: 4
Thanks!

I upgraded to 5.05 that fixed the crash issue I had with the script. Thanks so much!
Reply With Quote
  #20  
Old 11-21-2008, 09:36 PM
sfcavin sfcavin is offline
Registered User
 
Join Date: Nov 2008
Posts: 4
command file

Anyone know how to modify this script so that you can run multiple commands entered into a text file? This is my attempt but it's not working. Any help would be appreciated. Com.txt is the file containing the commands. It gets through the first session but craps out when it moves on to the next router. Thanks!!

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

Sub Main

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

Const DEVICE_FILE_PATH = "C:\script\sessionlist.txt"
Const COM_FILE_PATH = "C:\script\com.txt"

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

Dim fil
Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)

Dim com
set com = fso.OpenTextFile(COM_FILE_PATH)

Dim ip
Dim cnxnString
Dim command

'On Error Resume Next

While Not fil.AtEndOfStream

ip = fil.ReadLine

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

' Connect

crt.Screen.Synchronous = True

crt.Session.Connect cnxnString

While Not com.AtEndofStream

command = com.ReadLine

crt.Screen.WaitForString "#"

crt.Screen.Send command & vbCr

crt.Screen.WaitForString "#"


wend

com.close

crt.Screen.Synchronous = False

crt.Session.Disconnect

Wend

fil.Close

End Sub
Reply With Quote
  #21  
Old 11-23-2008, 02:40 PM
gokcell gokcell is offline
Registered User
 
Join Date: Oct 2007
Posts: 20
Apply your command and all your sides by using gokselyangin.vbs

In this situaiton there is 3 file. One is for iplist, second is for command adn the last one is script file which is gokselyangin.vbs.
In this script, program is going to login step by step from iplist.txt and then it apply again step by step necessary command from komut.txt until the end of line.

iplist.txt
------------------------
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5
192.168.1.6
192.168.1.7
192.168.1.8
192.168.1.9
192.168.1.10
-----------------------
komut.txt
----------------------
conf t
sh run conf int Gi1/14
----------------------
gokselyangin.vbs
-------------------------------------------------------------------
# $language = "VBScript"
# $interface = "1.0"

Sub Main
'Open the hosts file
set fso = CreateObject("Scripting.FileSystemObject")
Set fileHosts = fso.OpenTextFile("c:\iplist.txt",1,False)



do until fileHosts.AtEndOfStream
NextHost = fileHosts.ReadLine
NextHost = Replace(NextHost," ","")

if (Len(NextHost) > 1 and InStr(NextHost,"'") = 0) then
crt.session.connect("/telnet " & NextHost)
crt.Screen.Synchronous = True

crt.Screen.WaitForString "gin:"

crt.Screen.Send "usernama123" & vbCr

crt.Screen.WaitForString "assword:"

crt.Screen.Send "password123" & vbCr

crt.Screen.WaitForString "-->"

Set fileCommands = fso.OpenTextFile("c:\\komut.txt",1,False)
do until fileCommands.AtEndOfStream
NextCommand = fileCommands.ReadLine

crt.Screen.Send NextCommand & VbCr
crt.Screen.WaitForString "-->"
loop
fileCommands.Close

crt.Screen.Synchronous = False
crt.Sleep 5000

crt.session.disconnect()
end if

Loop

fileHosts.Close



Set fileHosts = Nothing
Set fileCommands = Nothing
Set fso = Nothing
crt.Quit

End Sub

---------------------------------------------------------------------
Goksel YANGIN
Computer Engineer


Quote:
Originally Posted by nxg
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!
Reply With Quote
  #22  
Old 11-24-2008, 08:43 AM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi sfcavin,

Thanks for posting the script files in use.

Can you explain more about how the script fails when it is supposed to move on to the next address in the list?
Does the script just hang without doing anything else, or does it display an error?

If the script is hanging, if you select 'Cancel' from the SecureCRT 'Script' menu, what is the error displayed?
Reply With Quote
  #23  
Old 11-25-2008, 09:53 AM
sfcavin sfcavin is offline
Registered User
 
Join Date: Nov 2008
Posts: 4
script

I actually borrowed from another script and came up with this. But it does this after the first command and each device and I have to hit ENTER to make it keep going to the next command:

switch#U

========================================================

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

Sub Main

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

Const DEVICE_FILE_PATH = "C:\script\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

' Connect

crt.Screen.Synchronous = True

crt.Session.Connect cnxnString

Set fileCommands = fso.OpenTextFile("c:\script\com.txt")
do until fileCommands.AtEndOfStream
NextCommand = fileCommands.ReadLine
crt.Screen.WaitForString "#"
crt.Screen.Send NextCommand & VbCr
crt.Screen.WaitForString "#"
loop
fileCommands.Close

crt.Screen.Synchronous = False

crt.Session.Disconnect

Wend

fil.Close

End Sub
Reply With Quote
  #24  
Old 11-26-2008, 09:15 AM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi sfcavin,

I'm not sure I understand what you mean by 'it does' 'switch#U'.

Can you provide me a screenshot of SecureCRT just before you hit 'Enter' to force the script to continue?
Feel free to send the screenshot to support@vandyke.com if you do not want to post it to the forum. If you send an e-mail, please set the subject line to 'Attn: Kevin Forum Thread 3235'
Reply With Quote
  #25  
Old 11-26-2008, 10:32 AM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi sfcavin,

In looking a little more at your script, there may be a correction we can make to resolve the issue.

Each time a connection in SecureCRT is made, crt.Screen.Synchronous is reset to 'False'.

Given this, if you move the crt.Screen.Synchronous line of your script to be called after the connection is made each time, do you see better behavior?

For example:

Code:
crt.Session.Connect cnxnString

crt.Screen.Synchronous = True
After making this change, does your script work as expected?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:58 AM.