G'day kylet,
"The goal is to have a value returned which is equal to the amount of authenticated users ..."
The first thing you should do is add strict and warnings to the start of your script. If you don't understand the messages they're outputting, also use diagnostics. Your script should start like this:
#!/usr/bin/perl use strict; use warnings; #use diagnostics; # optional use Getopt::Std; ...
Next, you should declare your variables. In most cases, my should be fine.
@strings[$i] (in @strings[$i] = $line;) is an array slice of only one element - almost certainly not what you want here! I'd recommend using push. I'd also recommend a more meaningful variable name.
For counting the lines containing the string "authenticated", you can simply use grep. However, be aware that the regexp /authenticated/ matches the strings: "authenticated", "unauthenticated", "not authenticated" and so on - you may want to be a bit more specific with what exactly you're matching.
Here's a skeleton example of the type of code you might want to use:
$ perl -Mstrict -Mwarnings -E ' my @in_strings; while (<>) { push @in_strings, $_; } my $count = grep /authenticated/ => @in_strings; say "count = $count"; ' qwerty asdfgh zxcvbn authenticated unauthenticated not authenticated count = 3
-- Ken
In reply to Re: Cisco PIX show command via telnet - unable to retrieve correct value
by kcott
in thread Cisco PIX show command via telnet - unable to retrieve correct value
by kylet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |