Script to return serial numbers of network switching equipment
Clash 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.
linux networking scripting remote
add a comment |Â
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.
linux networking scripting remote
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 haveno 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
add a comment |Â
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.
linux networking scripting remote
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.
linux networking scripting remote
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 haveno 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
add a comment |Â
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 haveno 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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered May 9 at 8:54
Mikhail Zakharov
1246
1246
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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