Problem with sending commands to mikrotik through telnet using expect script

2.3k Views Asked by At

my task is to create automatic script, which send commands to mikrotik router through telnet. I am trying to create "expect" script.

But I got stuck at command sending part. Standalone login works well (first code), but when i add another command (second code), console gets stuck at password (https://i.stack.imgur.com/oYFgL.jpg) for a few seconds and then i get output in picture: https://i.stack.imgur.com/TJwgt.jpg

First code for login to router. This one works great.

spawn telnet "12.12.13.44";
expect "Login: ";
send "admin\r";
expect "password: ";
send "admin\r";
interact;

and here is same code after adding the command, i like to send

spawn telnet "12.12.13.44";
expect "Login: ";
send "admin\r";
expect "password: ";
send "admin\r";
expect "> ";
send "ip firewall filter add chain=forward src-address=34.54.32.33 action=log\r";
exit;

I got the same output when using script without expect, which i tried before "expect"

(
echo open "12.12.13.44"
sleep 2
echo "admin"
sleep 2
echo "admin"
sleep 2
echo "ip firewall filter add chain=forward src-address=34.54.32.33 action=log"
sleep 2
echo "exit"
) | telnet

PS. I am using Debian version 8 and RouterOS 6.34.4

PPS. Previously mentionet devices are for uploading final solution, I have another router and computer(Ubuntu 18.10 and RouterOS 6.44.1), where i try my scripts and the output, whitch I showed in picture, apears in both of my routers and computers.

I will be grateful for any advice with my problem.

1

There are 1 best solutions below

0
On BEST ANSWER

I found solution at: https://wiki.mikrotik.com/wiki/Manual:Console_login_process#FAQ. The problematic output disappeared after I added "+t" after login name.