Hello;
I'm trying to make a python script to connect to port 12612 of localhost. Running the telnet command in linux, manually, it executes. However, in my python script, using the telnetlib library, it apparently is not connecting. I need to connect to the telnet console, and perform some tasks. Here is the code:
import os, glob, telnetlib, time
CAMINHO = "/home/admin/deploy"
HOST = "localhost"
PORT = "12612"
TIMEOUT = 2
filename = os.path.basename(__file__)
os.chdir(CAMINHO)
try:
tn = telnetlib.Telnet(HOST, PORT, TIMEOUT)
tn.set_debuglevel('DEBUG')
tn.open(HOST, PORT, TIMEOUT)
except ValueError:
print("Falha ao conectar")
for file in glob.glob("*.jar"):
arquivoAtual = file.split('_')[0]
comando = ("file://" + CAMINHO + "/" + file).strip()
tn.write(("uninstall " + arquivoAtual + "\n"))
tn.write("install " + comando + "\n")
tn.write("setbsl 5" + arquivoAtual + "\n")
tn.write("start " + arquivoAtual + "\n")
tn.write("exit" + "\n")
tn.close()
print('Concluido')