- using session name as hostname
- you should set gateway session and target session in connection manager
- can connect to target host directly
- but needed kinit on gateway server for sudo permission
# $language = "Python"
# $interface = "1.0"
GATEWAY_SESSION_NAME = "gateway.host.com"
KINIT_PASSWORD = "kinitpassword"
def Main():
# cancel connection to target host
if crt.Session.Connected:
crt.Session.Disconnect()
tab, error = 0, 0
target = ""
# if session saved in sub directory
target = crt.Session.Path.split("\\")[1]
# or
# target = crt.Session.Path
try:
# save tab object
tab = crt.Session.ConnectInTab("/S \"" + GATEWAY_SESSION_NAME + "\"")
except ScriptError:
error = crt.getLastErrorMessage()
if crt.Session.Connected and not error:
crt.Screen.Synchronous = True
while True:
if not crt.Screen.WaitForCursor(1):
break
row = crt.Screen.CurrentRow
prompt = crt.Screen.Get(row, 0, row, crt.Screen.CurrentColumn - 1)
prompt = prompt.strip()
crt.Screen.Send("kinit\n")
crt.Screen.WaitForString("host.com:")
crt.Screen.Send(KINIT_PASSWORD + "\n")
crt.Screen.WaitForString(prompt)
crt.Screen.Send("rlogin -l irteamsu " + target + "\n")
# change caption to target hostname
tab.Caption = target
crt.Screen.Synchronous = False
else:
crt.Dialog.MessageBox(error);
Main()