Is there a way to automate serial port connection and collect output to a file from some commands?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎11-22-2016 01:56 AM
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.
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.
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎11-22-2016 02:19 PM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎11-22-2016 02:12 PM
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
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
