cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to automate serial port connection and collect output to a file from some commands?

Is there a way to automate serial port connection and collect output to a file from some commands?

Ryan1
New Contributor
Using a Linux bash script, is there a way to log into an Extreme switch through the com port, run a command and collect the output to a file where the bash script was executed from? I need to automate collecting some data from around 100 switches that are not connected to a network where I can use ssh. I need to access them physically using the serial console only.



Manually it would be something like:
screen /dev/ttyUSB0 9600
admin

show version
exit

where I would then dump the version information to a file.

8 REPLIES 8

Erik_Auerswald
Contributor II
Hi Ryan,

the non-ASCII characters are terminal control codes, used e.g. by the pager. If you are gathering output automatically, you should issue the command "disable clipaging" before your show commands.

Erik

Ryan1
New Contributor
Konstantin,

Thanks for the detailed response! This works to create a file, but the file also including what non-ascii characters like: [!p [?3;4l [4l > [?1049

I also added the command: show port 1-48 information detail | include "Port:|Link State"

This stops outputting at around 32 ports.

Korsovsky__Kons
Extreme Employee
Hi Ryan.
One of the simplest ways would be to utilize Linux "expect" scripts. There is a lot of information about how to use them available in the Internet but here is a quick example on how you can use it in your case:

Create a text file named script.sh with following contents:
#!/usr/bin/expect -f
spawn screen /dev/ttyUSB0 9600
expect "login:"
send "admin\r"
expect "password:"
send "\r"
expect " # "
send "show version\r"
expect " # "
send "exit\r"Change access permissions of this file:
# chmod 755 script.sh
Run it and send output to some text file:
# ./script.sh > file.txtI hope it will help.

--
Konstantin

Gareth_Mitchell
Extreme Employee
Ryan

I think in screen you can use -L as a CLI switch, this outputs to screenlog.x which you could then grep for version.

Inside screen you can also do CTRL a + H (without the +) to toggle output on/off

I don't know if you can specifically capture only the version output in screen.

HTH

-Gareth
GTM-P2G8KFN