A
A
Alexander Nikitin2020-06-20 20:26:11
bash
Alexander Nikitin, 2020-06-20 20:26:11

Modify a BASH script to give the output of a specific command?

I'm trying to extract the states of Mikrotik's Ethernet interfaces with a script:

#! /bin/bash

HOST=$1;

(
echo -en 'admin\r'; #логин
sleep 1;
echo -en 'admin\r'; #пароль
sleep 2;
echo -en 'interface ethernet print\r'; #информация об интерфесах
sleep 2;
echo -en 'quit\r'; #вышел с устройства
) | telnet $HOST >> tmp.txt  #захожу телнетом и вывод работы скрипта сохраняю в файл


The output is:
Trying 192.168.1.88...
Connected to 192.168.1.88.
Escape character is '^]'.

MikroTik v6.43.12 (stable)
admin
Login: Password:

MMM MMM KKK TTTTTTTTTTT KKK

MMMM MMMM KKK TTTTTTTTTTT KKK

MMM MMMM MMM III KKK KKK RRRRRR OOOOOO TTT III KKK KKK

MMM MM MMM III KKKKK RRR RRR OOO OOO TTT III KKKKK

MMM MMM III KKK KKK RRRRRR OOO OOO TTT III KKK KKK

MMM MMM III KKK KKK RRR RRR OOOOOO TTT III KKK KKK

MikroTik RouterOS 6.43.12 (c) 1999-2018 www.mikrotik.com

[?] Gives the list of available commands

command [?] Gives help on the command and list of arguments

[Tab] Completes the command/word. If the input is ambiguous,

a second [Tab] gives possible options

/ Move up to base level

.. Move up one level

/command Use command at the base level

[9999B [ 9999B
Z [6n ] Only part of the output is displayed now.

interface ethernet print

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Alexandrov, 2020-06-20
@BRaVo_192

Don't use telnet. There is quite a normal api, well, or at least ssh.

K
Korben5E, 2020-06-22
@Korben5E

Write to a file on Mikrotik itself, then download this file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question