Scripting using /system telnet

Hi,

I’m trying to automate a task for energy meter data collection. It is available in the LAN with an IP address, and I can use TELNET for this unit. Following the “best girl’s friend” :wink: suggestion, I’m trying to make the following work:

/system script add name="telnet-script" source={

:local ip "192.XXX.X.XXX"
:local port "23"
:local fileName "IPM1.txt"

# Open Telnet session
/system telnet $ip port=$port
# Send login and commands
:delay 2
:put "ACC"
:delay 2
:put "Password"
:delay 2
:put "met e"

# Save the output to a file in the "sel735" directory
/tool fetch url="telnet://$ip/command-output" dst-path="sel735/$fileName"
}

Clearly, it stuck on “/system telnet $ip port=$port” and won’t continue until I manually force it to quit.

Any chance I can make something like that work without Containers?

I think telnet in Mikrotik is “interactive only”:
http://forum.mikrotik.com/t/script-telnet/63509/1

url="telnet://

do not exist on fetch.

If the device support SSH, that could be an option (/system ssh-exec)… But there not same for telnet.

“best girl’s friend” aka ChatGPT is not very familiar with ROS scripting, you should avoid it. If you cannot use SSH, you can try with expect tool (TCL syntax) in container to automate telnet login interaction and performing commands, here some example: https://www.baeldung.com/linux/telnet-automate-using-expect