Expect/telnet/testing tacacs on a cisco | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Expect/telnet/testing tacacs on a cisco

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-18-2010
popeye's Avatar
popeye popeye is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 11 July 2014, 11:24 AM EDT
Posts: 84
Thanks: 16
Thanked 1 Time in 1 Post
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 10.11.20.14 49
Trying 206.112.204.140, 49 ... Open

[Connection to 206.112.204.140 closed by foreign host]

route1#telnet 10.11.19.14 49
Trying 206.112.196.84, 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.



Code:
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 10.11.19.14 49\n"
expect {
   {Connection to}           {
                                    puts "$host tacacs ok"
                                    }
   {Connection timed out} {
                                    puts "$host tacacs nok"
                                    }
 }

Sponsored Links
    #2  
Old 11-23-2010
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
 
Join Date: Dec 2007
Last Activity: 13 August 2014, 11:44 PM EDT
Posts: 1,136
Thanks: 2
Thanked 88 Times in 85 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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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:23 PM.