Community discussions

MikroTik App
 
User avatar
wattev
just joined
Topic Author
Posts: 3
Joined: Fri May 24, 2024 9:17 pm

Scripting using /system telnet

Tue Sep 10, 2024 3:54 am

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?
 
jaclaz
Forum Guru
Forum Guru
Posts: 1621
Joined: Tue Oct 03, 2023 4:21 pm

Re: Scripting using /system telnet

Tue Sep 10, 2024 9:08 pm

I think telnet in Mikrotik is "interactive only":
viewtopic.php?t=69786
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12383
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scripting using /system telnet

Wed Sep 11, 2024 11:17 am

url="telnet://

do not exist on fetch.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 4037
Joined: Sun May 01, 2016 7:12 pm
Location: California
Contact:

Re: Scripting using /system telnet

Thu Sep 12, 2024 3:51 am

If the device support SSH, that could be an option (/system ssh-exec)... But there not same for telnet.
 
optio
Forum Veteran
Forum Veteran
Posts: 865
Joined: Mon Dec 26, 2022 2:57 pm

Re: Scripting using /system telnet

Mon Sep 16, 2024 7:05 pm

"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-a ... ing-expect

Who is online

Users browsing this forum: No registered users and 3 guests