kylet has asked for the wisdom of the Perl Monks concerning the following question:
The goal is to have a value returned which is equal to the amount of authenticated users (indicated by the amount of lines in the 'show uauth' command. Is there any glaring errors which may be stopping this script from completing successfully? I always seem to get a '0' returned, but I believe that is just the detault. Any help would be a huge help. Thanks Monks. Regards, Kyle#!/usr/bin/perl use Getopt::Std; # So we can do the processing of the command line opt +ions use IO::Socket; # For the connection $port = '23'; #telnet port $timeout=20; #connection timeout # Process the command line options die "Usage: $0 -r <router> -u <username> -p <password> -e <enable pass +word>\n" if (@ARGV < 6); exit if (!getopts('r:u:p:e:')); $username=$opt_u; $password=$opt_p; $enpassword=$opt_e; $router=$opt_r; main(); sub main(){ $i=0; # create a tcp connection to the specified host and port $handle = IO::Socket::INET->new(Proto => "tcp", PeerAddr => $router, PeerPort => $port, Timeout => $timeout) or return (print "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!\nCan't connect to port $port on $router\n!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); # split the program into two processes, identical twins die "can't fork: $!" unless defined($childpid = fork()); # the if{} block runs only in the parent process if ($childpid) { # copy the socket to array while (defined ($line = <$handle>)) { @strings[$i] = $line; $i++; } kill("TERM", $childpid); } # the else{} block runs only in the child process else { print $handle $username."\n" if $username; # Use a use +rname only if there is one; print $handle $password."\n"; print $handle "enable\n"; print $handle $enpassword."\n"; print $handle "sh uauth\n"; print $handle "exit\n"; close ($handle); exit; } #calculate the connected users $i=0; { foreach (@strings) {$i++ if /authenticated/; } print $i; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cisco PIX show command via telnet - unable to retrieve correct value
by hippo (Archbishop) on Mar 06, 2013 at 23:23 UTC | |
by kylet (Initiate) on Mar 07, 2013 at 11:32 UTC | |
|
Re: Cisco PIX show command via telnet - unable to retrieve correct value
by kcott (Archbishop) on Mar 08, 2013 at 01:43 UTC |