Trying to tweak the script to no avail
Hello,
I'm really new to scripting. I have to audit several equipment by sending a command line. However, I'm not able to use the script. Forum Moderator: To connect to an equipment I need to connect to a rebound server which I can easly do if I use : def main(): crt.Session.Connect("/s name of the session") main() Then I have to connect to the quipment using the specific command : ssh -l <Myusername> <IPaddress> then I get prompted to enter a password. I tried to tweak the script so that I could use it with this constraints, however it doesn't work. I was wondering if a charitable soul could help me. Thank you in advance. |
Hi mohenoun,
First, please clarify if by "the script", you were referencing sranbala's posted script here? Or VanDyke's Read Data example script that was referenced in the thread? By "rebound server", it sounds like you are going through a jump host. If the jump host is capable of port forwarding, I would recommend you make the connection using SecureCRT's dependent session feature. |
Quote:
Sorry my question wasn't clear. I'll try to structure it more :) Context : ========= I have to do an audit in my company for several cisco equipments, my idea was to launch a script in order to be able to do it automatically while going through a list of Ips vs commands. Constraint : ------------ To connect to equipment I need to connect to a rebound equipment. Basically if I wanted to connect to equipment A, in scripting it would be : crt.Session.Connect("/s rebound.win") crt.Screen.Send "ssh -l userid " & equipment A & chr(13) crt.Screen.WaitForString "Password:" crt.Screen.Send "Mypassword" & chr(13) crt.Screen.WaitForString "#" crt.Screen.Send chr(13) crt.Screen.Send "show ip bgp vpnv4 all summ | inc Idle" & chr(13) crt.Screen.Send "exit" & chr(13) Then connect again with crt.Screen.Send "ssh -l userid " & equipment B & chr(13) crt.Screen.WaitForString "Password:" crt.Screen.Send "Mypassword" & chr(13) crt.Screen.WaitForString "#" crt.Screen.Send chr(13) crt.Screen.Send "show ip bgp vpnv4 all summ | inc Idle" & chr(13) crt.Screen.Send "exit" & chr(13) If I keep my session in the rebound. If I open in different tabs I just use : crt.Session.Connect("/s rebound.win") crt.Screen.Send "ssh -l userid " & equipment A & chr(13) crt.Screen.WaitForString "Password:" crt.Screen.Send "Mypassword" & chr(13) crt.Screen.WaitForString "#" crt.Screen.Send chr(13) crt.Screen.Send "show ip bgp vpnv4 all summ | inc Idle" & chr(13) crt.Screen.Send "exit" & chr(13) And I log the session. This is how I'm doing it right now archaically ! Because my coding is limited. Script: ======== I found this on the website :https://forums.vandyke.com/showpost....94&postcount=1 RunCommandsOnMultipleHostsAndLogResults.vbs.txt Need: ===== I want to modify the script so that it connects the way I need to connect and the runs the commands using the hosts and commands files. I hope it is clear :) Thank you. |
Hi mohenoun,
Did you read the information about dependent session? Are you unable (jump server does not support port forwarding) to use this feature? Or just unwilling to try it? :) It's going to simplify things before we get into your actual script, which, by the way, includes multiple Send() calls without an intervening WaitForString(). This goes against the "best practice" outlined in the scripting manual (section 4.2) that there should be a WaitForString() following each Send() command. |
I can’t forward
Quote:
I just put forward the script as an exemple, I’m really new to this. Thus I wanted to use a script that was following best practices. But I got lost in the coding and couldn’t figure out what to change and where and how to do it in a clean way. Thank you for your help. |
Actually, I just want to know what to change in https://forums.vandyke.com/showpost....94&postcount=1
Since my jump server doesn't seem to allow port forwarding. |
Hi mohenoun,
For your objective, I think you will be better off using this jump host script example. Give it a shot and let me know what obstacles you run into. |
Quote:
I changed the ssh connection line to : strCommand = "ssh -l d91910 " & vHosts(nIndex) crt.Screen.Send strCommand & vbcr I'm getting : Jumpserver#ssh -l d91910 PE2 Password: Enter Old Password: Password: [Connection to PE2 aborted: error status 0] jumpserver# jumpserver# jumpserver# |
Quote:
PE2# But it doesn't go to the following device, I tried changing $ to # as a successful indicator |
Quote:
It's working ! Is there a way to make it save results in separate files ? |
Hi mohenoun,
I am glad to hear of your progress. So is logging configured in your rebound server session? If so, I would suggest you just set a log file name that includes the host as part of it and stop/start logging within the Do Loop/Select Case construct, before sending commands. Maybe something like this: Code:
crt.Session.LogFileName = "C:\Logs\" & vHosts(nIndex) & "-%M%D%y.txt" |
Quote:
The computer is literally a black box so it's OK without AUTH key :) I can't configure it anyway. I added crt.Session.Connect("/s jumpstartserver") crt.Screen.WaitForString "Jumpstartserver#" And it's working wonders. The only thing that I can't seem to figure out how to do, is to log a seperate file for each machine I connect to in order to use them afterward in excel. Any example on a code I could add to log just the results of my commands in files named according to the host list ? thanks :) |
Quote:
|
Hi mohenoun,
I provided an example for logging. If I have any suggestion for reading a file, it won't be until Monday at the earliest. If feeling ambitious, you might just look at how it was done in the RunCommands example and try to add that code to this script. :) |
Thanks :)
Quote:
I'll try it today |
All times are GMT -6. The time now is 09:36 PM. |