#
#==========================================================
#
# Abs: Python script to perform commands on terminal 
#      servers via telnet (Called from iocTSmgr)
#
# Created: Ken Brobeck  Nov 11, 2019
# 
#----------------------------------------------------------
# -Mods:
#
#
#---------------------------------------------------------
import sys
import telnetlib

#Read command line arguments and assign
#---------------------------------------
user=sys.argv[1]
password=sys.argv[2]
HOST=sys.argv[3]
command=sys.argv[4]

tn = telnetlib.Telnet(HOST)

#- Sometimes prompts (login and password) have caps
# --------------------------------------------------
tn.read_until(b"ogin: ")
tn.write(user + "\n")
if password:
    tn.read_until(b"assword: ")
    tn.write(password + "\n")

tn.write(command + "\n")
tn.write("exit\n")

print tn.read_all()
