#1
|
|||
|
|||
Automate ssh login from one system to another
Hi,
I am running SecureCRT v5.0.0 (Build 992) and wanted to find out how I could script doing a ssh to a unix server with a hardcoded username and password, and then from that server telnet to a remote device. The only input parameter would be the hostname/ipaddress of the remote device. Any help would be very appreciated. |
#2
|
||||
|
||||
Hi,
One way to do this would be to call a script with a command line such as this: securecrt /s server1 /script c:\ssh-to-arg.vbs /arg server2The ssh-to-arg.vbs script could be as simple as this: Code:
Crt.Screen.Send "ssh " & crt.Arguments.GetArg(0) & vbcr
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#3
|
|||
|
|||
Still not working
Hi Mike,
Thanks for the response but it does not seem to work. I get a pop-up window with the error - <hostname> was not found in the session database. Any help would be very appreciated. Thanks |
#4
|
||||
|
||||
Hi 1720,
The sample command that Mike provided is calling a session (server1) to start the connection. The error indicates that SecureCRT could not find the session name specified in the command line. Does a session with the name that was specified after the '/S', exist in the session database? If so, does the session appear inside a folder when viewed in the 'Connect' dialog in SecureCRT?
__________________
Thanks, Teresa Teresa Nygren |
#5
|
|||
|
|||
Hi Teresa,
No there is no session saved with that name. What I am trying to do is to ssh to my server with a known username/password. And from there, telnet or ssh to a second device where the second device is passed as an argument and the second set of username/password are prompted. So far I have the following - # $language = "VBScript" # $interface = "1.0" ' Connect to an SSH server using the SSH2 protocol. Specify the ' username and password and hostname on the command line as well as ' some SSH2 protocol specific options. Sub Main Dim host host = "10.20.4.205" Dim user user = "engineer" Dim router_username router_username = crt.Dialog.Prompt("Enter your TACACS ID for ", & host "TACACS Login") Dim passwd passwd = "mypasswd" ' Build a command-line string to pass to the Connect method. ' cmd = "/SSH2 /L " & user & " /PASSWORD " & passwd & " /C 3DES /M MD5 " & host crt.Session.Connect cmd crt.Screen.Send "ssh -l " & router_username " pcpf11sb.smart.net" & chr(13) crt.Screen.WaitForString "Are you sure you want to continue connecting (yes/no)? " crt.Screen.Send "yes" & chr(13) crt.Screen.WaitForString & router_username "@pcpf11sb.smart.net's password: " ' Prompt for a password instead of embedding it in a script... ' 'Dim passwd_device 'passwd_device = crt.Dialog.Prompt("Enter password for " pcpf11sb, "Login", "",True) crt.Screen.Send "newyork1" & chr(13) End Sub |
#6
|
||||
|
||||
Hi 1720,
That does explain the error message. In this case, it may be better to pass the arguments to the script and then use them in the script. A simple example of a script that will message box the arguments passed to it would be: Code:
Main Sub Main() If WScript.Arguments.Count > 0 then For nIndex = 1 to WScript.Arguments.Count szArgs = szArgs & vbcrlf & "Arg #" & nIndex & ": " & WScript.Arguments(nIndex - 1) Next else szArgs = "(No args specified for this script)" end if MsgBox "Arguments sent to this script include: " & vbcrlf & szArgs End Sub Since the arguments would contain several parts of the ssh command, he arguments would need to be entered in the same order each time. If they weren't, then there would be issues constructing the command line. As this is a VBScript option, more information on the Arguments array can be found on Microsoft's scripting help pages. Would this be an option that could help?
__________________
Thanks, Teresa Teresa Nygren |
#7
|
|||
|
|||
Hi Teresa,
The script is almost working except it is not accepting command line args. So here is what I am doing from cmd line - securecrt /script .\scripts\ssh.vbs /arg test I get the following error in a popup window - Error: Object required: 'WScript' Here is my updated script - # $language = "VBScript" # $interface = "1.0" ' Connect to an SSH server using the SSH2 protocol. Specify the ' username and password and hostname on the command line as well as ' some SSH2 protocol specific options. Sub Main Dim host host = "10.20.4.205" Dim user user = "engineer" Dim passwd passwd = "mypasswd" Dim device device = WScript.Argument(0) Dim user_name user_name = crt.Dialog.Prompt("Enter your TACACS ID for ", user_name, "TACACS Login",False) ' Build a command-line string to pass to the Connect method. cmd = "/SSH2 /L " & user & " /PASSWORD " & passwd & " /C 3DES /M MD5 " & host crt.Session.Connect cmd crt.Screen.Send "ssh -l " & user_name & " " & device & chr(13) crt.Screen.WaitForString "Are you sure you want to continue connecting (yes/no)? " crt.Screen.Send "yes" & chr(13) End Sub |
#8
|
||||
|
||||
Hi 1720,
I think that I may have miss understood how the script is being run. If SecureCRT is used to start the script, then it is the script object host is SecureCRT not wscript. The wscript.arguments object will not be available but crt.arguments will be available. If the following line: device = WScript.Argument(0) Is changed to: device = crt.Arguments(0) Does the script work correctly?
__________________
Thanks, Teresa Teresa Nygren |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|