Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Expect/telnet/testing tacacs on a cisco

Shell Programming and Scripting

Thread Tools Search this Thread Display Modes
Old Unix and Linux 10-18-2010
popeye's Unix or Linux Image
popeye popeye is offline
Registered User
Join Date: Mar 2008
Last Activity: 8 February 2017, 12:38 PM EST
Posts: 97
Thanks: 23
Thanked 2 Times in 2 Posts
Expect/telnet/testing tacacs on a cisco

At times I find the need to test that the tacacs port 49 is open.
The code below works but is painfully slow because I have to wait on the timeouts.

Examples of possible responds

router1#telnet 49
Trying, 49 ... Open

[Connection to closed by foreign host]

route1#telnet 49
Trying, 49 ...
% Connection timed out; remote host not responding
End Examples

I would like to capture and act on the "Trying" lines

... Open = tacacs port good
... = tacacs port bad
end remote telent
end local telnet

But I dont know how to tell expect how to grab those responses from the router. Help would be much appreciated.

The entire code is given below.

while { [gets $ifil host] >=0 } {
set timeout 600
spawn telnet $host
expect ":"
send "myusername\n"
expect ":"
send "mypassword\n"
expect ">"
send "en\n"
expect ":"
send "mypassword2\n"
expect "#"
sleep 3
send "telnet 49\n"
expect {
   {Connection to}           {
                                    puts "$host tacacs ok"
   {Connection timed out} {
                                    puts "$host tacacs nok"

Sponsored Links
Old Unix and Linux 11-23-2010
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
Join Date: Dec 2007
Last Activity: 28 July 2016, 2:18 PM EDT
Posts: 1,152
Thanks: 4
Thanked 92 Times in 89 Posts
do you have to use expect/telnet? develop a simple socket program in Perl, Python or whatever langauge. nc is also a great utility to test something like this.
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting genewolfe Shell Programming and Scripting 1 10-01-2009 11:12 AM
Webpage to Telnet via Perl and Expect: Telnet problem? jondo Shell Programming and Scripting 1 07-22-2008 12:35 AM
Perl telnet to cisco router and compare the ping ms optimus Shell Programming and Scripting 4 08-27-2007 02:28 AM
Testing telnet connections in a script dikiee Shell Programming and Scripting 0 01-12-2007 08:40 AM

All times are GMT -4. The time now is 08:42 AM.