Script to return serial numbers of network switching equipment

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have been tasked with doing a survey and inventory of a very large network. I specifically need to get the serial numbers of 1000+ Avaya switches and routers. All are accessible via either telnet or ssh from my workstation. Almost all of them are accessible with the same user name and password. Some will have only telnet access and some will have only ssh access.



Once logged in, I can get the serial number like this:



en[crlf] (to enable cli command mode)



show tec[crlf] (returns technical information of device)



[3x spacebar] (to make sure serial number is displayed)



q (to stop displaying more data and return to cli prompt)



exit[crlf] (to end the terminal session)



From the output generated by that I can then grep the serial numbers.



So my problem is automating this in a bash script or something similar to generate a list of serial numbers against the given IP addresses of the devices.



The script should ideally:



1.Read the IP address of the device from a file.



2.Try to login with ssh credentials 1 (if failed, try credentials 2)



3.If failed, telnet credentials 1 (if failed, try credentials 2)



4.If all failed, write "Failed to login" to output file.



5.If successful, write device IP address and serial to output file.



6.Repeat for next device IP in list.



7.Using plain text username and passwords in this situation is not an issue.



I am using the latest Ubuntu Linux on my workstation.



Hoping someone can give me some advice on accomplishing this task. I do not look forward to manually logging into 1000 switches.







share|improve this question

















  • 1




    man expect.
    – AlexP
    May 9 at 8:41






  • 2




    "[3x spacebar] (to make sure serial number is displayed)" -- if that's to skip over some "next page" prompts, you might want to see if the switches have some command to disable paging. Some Cisco-like CLI:s have no page for that. If there isn't something like that, you may need to take timing into account there, it might not be safe to assume that you can just spam the characters there up front.
    – ilkkachu
    May 9 at 8:43










  • expect or Ansible if you are interesting in exploring that field.
    – Rui F Ribeiro
    May 9 at 9:07











  • Could SNMP be another option? Like: snmpget -v2c -Ovq -c public "$ip_address" .1.3.6.1.2.1.47.1.1.1.1.11.1
    – Stéphane Chazelas
    May 9 at 9:22















up vote
0
down vote

favorite












I have been tasked with doing a survey and inventory of a very large network. I specifically need to get the serial numbers of 1000+ Avaya switches and routers. All are accessible via either telnet or ssh from my workstation. Almost all of them are accessible with the same user name and password. Some will have only telnet access and some will have only ssh access.



Once logged in, I can get the serial number like this:



en[crlf] (to enable cli command mode)



show tec[crlf] (returns technical information of device)



[3x spacebar] (to make sure serial number is displayed)



q (to stop displaying more data and return to cli prompt)



exit[crlf] (to end the terminal session)



From the output generated by that I can then grep the serial numbers.



So my problem is automating this in a bash script or something similar to generate a list of serial numbers against the given IP addresses of the devices.



The script should ideally:



1.Read the IP address of the device from a file.



2.Try to login with ssh credentials 1 (if failed, try credentials 2)



3.If failed, telnet credentials 1 (if failed, try credentials 2)



4.If all failed, write "Failed to login" to output file.



5.If successful, write device IP address and serial to output file.



6.Repeat for next device IP in list.



7.Using plain text username and passwords in this situation is not an issue.



I am using the latest Ubuntu Linux on my workstation.



Hoping someone can give me some advice on accomplishing this task. I do not look forward to manually logging into 1000 switches.







share|improve this question

















  • 1




    man expect.
    – AlexP
    May 9 at 8:41






  • 2




    "[3x spacebar] (to make sure serial number is displayed)" -- if that's to skip over some "next page" prompts, you might want to see if the switches have some command to disable paging. Some Cisco-like CLI:s have no page for that. If there isn't something like that, you may need to take timing into account there, it might not be safe to assume that you can just spam the characters there up front.
    – ilkkachu
    May 9 at 8:43










  • expect or Ansible if you are interesting in exploring that field.
    – Rui F Ribeiro
    May 9 at 9:07











  • Could SNMP be another option? Like: snmpget -v2c -Ovq -c public "$ip_address" .1.3.6.1.2.1.47.1.1.1.1.11.1
    – Stéphane Chazelas
    May 9 at 9:22













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have been tasked with doing a survey and inventory of a very large network. I specifically need to get the serial numbers of 1000+ Avaya switches and routers. All are accessible via either telnet or ssh from my workstation. Almost all of them are accessible with the same user name and password. Some will have only telnet access and some will have only ssh access.



Once logged in, I can get the serial number like this:



en[crlf] (to enable cli command mode)



show tec[crlf] (returns technical information of device)



[3x spacebar] (to make sure serial number is displayed)



q (to stop displaying more data and return to cli prompt)



exit[crlf] (to end the terminal session)



From the output generated by that I can then grep the serial numbers.



So my problem is automating this in a bash script or something similar to generate a list of serial numbers against the given IP addresses of the devices.



The script should ideally:



1.Read the IP address of the device from a file.



2.Try to login with ssh credentials 1 (if failed, try credentials 2)



3.If failed, telnet credentials 1 (if failed, try credentials 2)



4.If all failed, write "Failed to login" to output file.



5.If successful, write device IP address and serial to output file.



6.Repeat for next device IP in list.



7.Using plain text username and passwords in this situation is not an issue.



I am using the latest Ubuntu Linux on my workstation.



Hoping someone can give me some advice on accomplishing this task. I do not look forward to manually logging into 1000 switches.







share|improve this question













I have been tasked with doing a survey and inventory of a very large network. I specifically need to get the serial numbers of 1000+ Avaya switches and routers. All are accessible via either telnet or ssh from my workstation. Almost all of them are accessible with the same user name and password. Some will have only telnet access and some will have only ssh access.



Once logged in, I can get the serial number like this:



en[crlf] (to enable cli command mode)



show tec[crlf] (returns technical information of device)



[3x spacebar] (to make sure serial number is displayed)



q (to stop displaying more data and return to cli prompt)



exit[crlf] (to end the terminal session)



From the output generated by that I can then grep the serial numbers.



So my problem is automating this in a bash script or something similar to generate a list of serial numbers against the given IP addresses of the devices.



The script should ideally:



1.Read the IP address of the device from a file.



2.Try to login with ssh credentials 1 (if failed, try credentials 2)



3.If failed, telnet credentials 1 (if failed, try credentials 2)



4.If all failed, write "Failed to login" to output file.



5.If successful, write device IP address and serial to output file.



6.Repeat for next device IP in list.



7.Using plain text username and passwords in this situation is not an issue.



I am using the latest Ubuntu Linux on my workstation.



Hoping someone can give me some advice on accomplishing this task. I do not look forward to manually logging into 1000 switches.









share|improve this question












share|improve this question




share|improve this question








edited May 9 at 9:35









Jeff Schaller

31.1k846105




31.1k846105









asked May 9 at 6:37









Doep100

1




1







  • 1




    man expect.
    – AlexP
    May 9 at 8:41






  • 2




    "[3x spacebar] (to make sure serial number is displayed)" -- if that's to skip over some "next page" prompts, you might want to see if the switches have some command to disable paging. Some Cisco-like CLI:s have no page for that. If there isn't something like that, you may need to take timing into account there, it might not be safe to assume that you can just spam the characters there up front.
    – ilkkachu
    May 9 at 8:43










  • expect or Ansible if you are interesting in exploring that field.
    – Rui F Ribeiro
    May 9 at 9:07











  • Could SNMP be another option? Like: snmpget -v2c -Ovq -c public "$ip_address" .1.3.6.1.2.1.47.1.1.1.1.11.1
    – Stéphane Chazelas
    May 9 at 9:22













  • 1




    man expect.
    – AlexP
    May 9 at 8:41






  • 2




    "[3x spacebar] (to make sure serial number is displayed)" -- if that's to skip over some "next page" prompts, you might want to see if the switches have some command to disable paging. Some Cisco-like CLI:s have no page for that. If there isn't something like that, you may need to take timing into account there, it might not be safe to assume that you can just spam the characters there up front.
    – ilkkachu
    May 9 at 8:43










  • expect or Ansible if you are interesting in exploring that field.
    – Rui F Ribeiro
    May 9 at 9:07











  • Could SNMP be another option? Like: snmpget -v2c -Ovq -c public "$ip_address" .1.3.6.1.2.1.47.1.1.1.1.11.1
    – Stéphane Chazelas
    May 9 at 9:22








1




1




man expect.
– AlexP
May 9 at 8:41




man expect.
– AlexP
May 9 at 8:41




2




2




"[3x spacebar] (to make sure serial number is displayed)" -- if that's to skip over some "next page" prompts, you might want to see if the switches have some command to disable paging. Some Cisco-like CLI:s have no page for that. If there isn't something like that, you may need to take timing into account there, it might not be safe to assume that you can just spam the characters there up front.
– ilkkachu
May 9 at 8:43




"[3x spacebar] (to make sure serial number is displayed)" -- if that's to skip over some "next page" prompts, you might want to see if the switches have some command to disable paging. Some Cisco-like CLI:s have no page for that. If there isn't something like that, you may need to take timing into account there, it might not be safe to assume that you can just spam the characters there up front.
– ilkkachu
May 9 at 8:43












expect or Ansible if you are interesting in exploring that field.
– Rui F Ribeiro
May 9 at 9:07





expect or Ansible if you are interesting in exploring that field.
– Rui F Ribeiro
May 9 at 9:07













Could SNMP be another option? Like: snmpget -v2c -Ovq -c public "$ip_address" .1.3.6.1.2.1.47.1.1.1.1.11.1
– Stéphane Chazelas
May 9 at 9:22





Could SNMP be another option? Like: snmpget -v2c -Ovq -c public "$ip_address" .1.3.6.1.2.1.47.1.1.1.1.11.1
– Stéphane Chazelas
May 9 at 9:22











1 Answer
1






active

oldest

votes

















up vote
3
down vote













For automation of interactive CLI processes you can use "Expect" or its alternatives: https://en.wikipedia.org/wiki/Expect. The simplest Expect script example:



spawn telnet foo.bar.com 
expect ogin send luserr
expect assword send TopSecretr
send "who am ir"
send "exitr"
expect eof





share|improve this answer





















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442694%2fscript-to-return-serial-numbers-of-network-switching-equipment%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    For automation of interactive CLI processes you can use "Expect" or its alternatives: https://en.wikipedia.org/wiki/Expect. The simplest Expect script example:



    spawn telnet foo.bar.com 
    expect ogin send luserr
    expect assword send TopSecretr
    send "who am ir"
    send "exitr"
    expect eof





    share|improve this answer

























      up vote
      3
      down vote













      For automation of interactive CLI processes you can use "Expect" or its alternatives: https://en.wikipedia.org/wiki/Expect. The simplest Expect script example:



      spawn telnet foo.bar.com 
      expect ogin send luserr
      expect assword send TopSecretr
      send "who am ir"
      send "exitr"
      expect eof





      share|improve this answer























        up vote
        3
        down vote










        up vote
        3
        down vote









        For automation of interactive CLI processes you can use "Expect" or its alternatives: https://en.wikipedia.org/wiki/Expect. The simplest Expect script example:



        spawn telnet foo.bar.com 
        expect ogin send luserr
        expect assword send TopSecretr
        send "who am ir"
        send "exitr"
        expect eof





        share|improve this answer













        For automation of interactive CLI processes you can use "Expect" or its alternatives: https://en.wikipedia.org/wiki/Expect. The simplest Expect script example:



        spawn telnet foo.bar.com 
        expect ogin send luserr
        expect assword send TopSecretr
        send "who am ir"
        send "exitr"
        expect eof






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered May 9 at 8:54









        Mikhail Zakharov

        1246




        1246






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442694%2fscript-to-return-serial-numbers-of-network-switching-equipment%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay