<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Is there a way to automate serial port connection and collect output to a file from some commands? in ExtremeSwitching (EXOS/Switch Engine)</title>
    <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45259#M11248</link>
    <description>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.&lt;BR /&gt;
&lt;BR /&gt;
     &lt;BR /&gt;
&lt;BR /&gt;
    Manually it would be something like:&lt;BR /&gt;
screen /dev/ttyUSB0 9600&lt;BR /&gt;
admin&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
show version&lt;BR /&gt;
exit&lt;BR /&gt;
&lt;BR /&gt;
where I would then dump the version information to a file.&lt;BR /&gt;
&lt;BR /&gt;&lt;/B&gt;</description>
    <pubDate>Tue, 22 Nov 2016 09:56:00 GMT</pubDate>
    <dc:creator>Ryan1</dc:creator>
    <dc:date>2016-11-22T09:56:00Z</dc:date>
    <item>
      <title>Is there a way to automate serial port connection and collect output to a file from some commands?</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45259#M11248</link>
      <description>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.&lt;BR /&gt;
&lt;BR /&gt;
     &lt;BR /&gt;
&lt;BR /&gt;
    Manually it would be something like:&lt;BR /&gt;
screen /dev/ttyUSB0 9600&lt;BR /&gt;
admin&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
show version&lt;BR /&gt;
exit&lt;BR /&gt;
&lt;BR /&gt;
where I would then dump the version information to a file.&lt;BR /&gt;
&lt;BR /&gt;&lt;/B&gt;</description>
      <pubDate>Tue, 22 Nov 2016 09:56:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45259#M11248</guid>
      <dc:creator>Ryan1</dc:creator>
      <dc:date>2016-11-22T09:56:00Z</dc:date>
    </item>
    <item>
      <title>RE: Is there a way to automate serial port connection and collect output to a file from some commands?</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45260#M11249</link>
      <description>Ryan&lt;BR /&gt;
&lt;BR /&gt;
I think in screen you can use -L as a CLI switch, this outputs to screenlog.x which you could then grep for version.&lt;BR /&gt;
&lt;BR /&gt;
Inside screen you can also do CTRL a + H (without the +) to toggle output on/off&lt;BR /&gt;
&lt;BR /&gt;
I don't know if you can specifically capture only the version output in screen.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
&lt;BR /&gt;
-Gareth</description>
      <pubDate>Tue, 22 Nov 2016 22:12:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45260#M11249</guid>
      <dc:creator>Gareth_Mitchell</dc:creator>
      <dc:date>2016-11-22T22:12:00Z</dc:date>
    </item>
    <item>
      <title>RE: Is there a way to automate serial port connection and collect output to a file from some commands?</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45261#M11250</link>
      <description>Hi Ryan.&lt;BR /&gt;
 One of the simplest ways would be to utilize Linux "&lt;A href="https://en.wikipedia.org/wiki/Expect" target="_blank" rel="nofollow noreferrer noopener"&gt;expect&lt;/A&gt;" 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:&lt;BR /&gt;
&lt;BR /&gt;
Create a text file named script.sh with following contents:&lt;BR /&gt;
#!/usr/bin/expect -f&lt;BR /&gt;
spawn screen /dev/ttyUSB0 9600&lt;BR /&gt;
expect "login:"&lt;BR /&gt;
send "admin\r"&lt;BR /&gt;
expect "password:"&lt;BR /&gt;
send "\r"&lt;BR /&gt;
expect " # "&lt;BR /&gt;
send "show version\r"&lt;BR /&gt;
expect " # "&lt;BR /&gt;
send "exit\r"Change access permissions of this file:&lt;BR /&gt;
# chmod 755 script.sh&lt;BR /&gt;
Run it and send output to some text file:&lt;BR /&gt;
# ./script.sh &amp;gt; file.txtI hope it will help.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
 Konstantin</description>
      <pubDate>Tue, 22 Nov 2016 22:19:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45261#M11250</guid>
      <dc:creator>Korsovsky__Kons</dc:creator>
      <dc:date>2016-11-22T22:19:00Z</dc:date>
    </item>
    <item>
      <title>RE: Is there a way to automate serial port connection and collect output to a file from some commands?</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45262#M11251</link>
      <description>Konstantin,&lt;BR /&gt;
&lt;BR /&gt;
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 &amp;gt; [?1049&lt;BR /&gt;
&lt;BR /&gt;
I also added the command:  show port 1-48 information detail | include "Port:|Link State"&lt;BR /&gt;
&lt;BR /&gt;
This stops outputting at around 32 ports.&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Nov 2016 09:19:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45262#M11251</guid>
      <dc:creator>Ryan1</dc:creator>
      <dc:date>2016-11-23T09:19:00Z</dc:date>
    </item>
    <item>
      <title>RE: Is there a way to automate serial port connection and collect output to a file from some commands?</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45263#M11252</link>
      <description>Hi Ryan,&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
Erik</description>
      <pubDate>Wed, 23 Nov 2016 14:34:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45263#M11252</guid>
      <dc:creator>Erik_Auerswald</dc:creator>
      <dc:date>2016-11-23T14:34:00Z</dc:date>
    </item>
    <item>
      <title>RE: Is there a way to automate serial port connection and collect output to a file from some commands?</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45264#M11253</link>
      <description>Hi Ryan,&lt;BR /&gt;
&lt;BR /&gt;
That could be a result of screen trying to control the terminal. Screen is terminal oriented and controls the output visible on the terminal, including scrolling the currently displayed up one line to display the next line. That does not work well together with expect.&lt;BR /&gt;
&lt;BR /&gt;
A line oriented program like cu (Debian/Ubuntu package cu) might work better with expect, but I haven't used it for many years.&lt;BR /&gt;
&lt;BR /&gt;
I am using expect together with SSH or telnet (in a lab) to a console server connecting the switch consoles and cannot test with a direct serial connection at this time.&lt;BR /&gt;
&lt;BR /&gt;
Hope to help,&lt;BR /&gt;
Erik</description>
      <pubDate>Wed, 23 Nov 2016 17:42:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45264#M11253</guid>
      <dc:creator>Erik_Auerswald</dc:creator>
      <dc:date>2016-11-23T17:42:00Z</dc:date>
    </item>
    <item>
      <title>RE: Is there a way to automate serial port connection and collect output to a file from some commands?</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45266#M11255</link>
      <description>You were both right; I had better luck with cu.  It’s not perfect, but it will work.  In order to parse the redirected file, I had to:&lt;BR /&gt;
&lt;BR /&gt;
&lt;OL&gt; 
&lt;LI&gt;Use sed to remove a line that that  always contained a non-ascii string 
&lt;/LI&gt;&lt;LI&gt;Use sed to do some find and replaces to clean up a couple lines that I need to parse and couldn't just delete. 
&lt;/LI&gt;&lt;LI&gt;I am also using dos2unix on the file before I parse it.  This might not be needed now, but it was helping when I was  using screen, so I left that in.&lt;/LI&gt;&lt;/OL&gt;Sometimes accessing the switch fails, and looking at the dump file, it  looks like the expect and send are out of sync with the switch, but I can add a  retry to work with it.  Anyways, its definitely  a workable solution and super helpful!   Thank you guys!     One more question, when I access the switch manually using  cu or screen, after I am done, I type “exit”, but you are not fully out of the  terminal session.  It’s more like I just  logged out.  I am sitting at a “login”  prompt.  In a situation where my Linux OS  has Xwindows, I can just close the terminal, but in an OS where there is no Xwindows,  I have to switch to another terminal, and kill the PID to end the session.  What’s the right way to fully exit from a cu terminal  session under CLI?&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Thu, 24 Nov 2016 12:18:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/is-there-a-way-to-automate-serial-port-connection-and-collect/m-p/45266#M11255</guid>
      <dc:creator>Ryan1</dc:creator>
      <dc:date>2016-11-24T12:18:00Z</dc:date>
    </item>
  </channel>
</rss>

