0

I'm modifying a script in python to run in securecrt 8.5.2 in order to backup the running-config of some cisco ASR9K equipment I have in charge, but the script seems to end abruptly after the second sucessful ssh2 hop (2nd tab) and does not send the commands I scripted (the exit in this specifical example), here's the code I have, as I'd said it's a modified version of the one's in vandyke page for opening ssh2.

One important thing is that I have to tab each session of each individual routers, because it doesn't permit doing an ssh direct from the active cli, so I had to improvise and implement this "connect in TAB", I'm suspecting that the secureCRT doesn't know if it is in the new tab I've opened so, it doesn't know where to send the commands.

I was playing with the line 30, but it doesn't seem to have any effect. I was changing the expected text, but it doesn't seem to recognize the correct tab or doesn't read the correct one.

Personal Background: A complete beginner in the python language.

# $language = "python"
# $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.

host = "X.X.X.a"
host2 = "X.X.X.b"

def main():
    crt.Screen.Synchronous = True
    # Prompt for a username and password instead of embedding it in a script...
    #
    usr = crt.Dialog.Prompt("Enter the user name for" + host, "Username", "", True)
    passwd = crt.Dialog.Prompt("Enter TACACS+ for" + host, "Login", "", True)

    # Build a command-line string to pass to the Connect method.
    cmd = "/SSH2 /L %s /PASSWORD %s /C AES-128-CTR /M SHA1 %s" % (usr, passwd, host)
    crt.Session.Connect(cmd)
    crt.Screen.WaitForString("X.X.X.a#")
    crt.Screen.Send("copy running-config tftp:\r")
    crt.Screen.WaitForString("Host name or IP address (control-c to abort): []?")
    crt.Screen.Send("tftpserver.com\r") 
    crt.Screen.WaitForString("Destination file name (control-c to abort): [running-config]?")
    crt.Screen.Send("X.X.X.a_running_config\r")
    crt.Screen.WaitForString("X.X.X.a")
    cmd2 = "/SSH2 /L %s /PASSWORD %s /C AES-128 /M SHA1 %s" % (usr, passwd, host2)
    crt.Session.ConnectInTab(cmd2)
    crt.Screen.WaitForString("X.X.X.b#")
    crt.Screen.Send("exit\r")


main()

crt.Session.ConnectInTab(cmd2)

It connects to the equipment in a new tab, but what I expect is that the script will keep doing the same it did for the host1 (X.X.X.a) and send the same boring stuff to the host2 (X.X.X.b) via ssh2 tab, and continue the itterative process until I do this for all the equipments I need.

Thanks for reading me.

Dakrutz
  • 1
  • 1

1 Answers1

0

Well it's not even funny easy was to solve this very sub-optimal code or script but it was not much of a problem, the only thing is that I had to dissconect to the previous session when I inyected all the commands, so in order to put the cursor on the new tab, the previous session must be dissconected first.

The solution?

crt.Session.Disconnect()

Dakrutz
  • 1
  • 1