Discussion Locked

Anyone know Perl?

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have this script that I have hacked together and I can't seem to get it to run.
The Net::Telnet::Cisco is giving me a big issue. It says that the package is installed, but how knows here is the code:

#!/usr/bin/perl
use Net::Ping;
$host = '111.111.111.111;
print "starting...";
print "starting...";
$counter = 0;

while ($counter <=4)
{
$p = Net::Ping->new("icmp", 2);
$counter++ unless $p->ping($host);
print "pinging...";
if ($p->ping($host))
{ $counter = 0;
print "$host is alive.\n";
}
sleep (10);
if ($counter = 3)
{
&noshut($counter);
print "$host is unreachable switching to ISDN.\n";
}

}

$p->close();

sub noshut
{
use Net::Telnet::Cisco;

my $cs = Net::Telnet::Cisco->( Host => '192.168.0.1' );
$cs->login( 'pword', 'uname' );

# Turn off paging
my @cmd_output = $cs->cmd( 'terminal length 0' );

# Execute a command
@cmd_output = $cs->cmd( 'config t' );
print @cmd_output;
@cmd_output = $cs->cmd( 'int e1' );
print @cmd_output;
@cmd_output = $cs->cmd( 'shut' );
print @cmd_output;
sleep (350);
print "sleeping...";
@cmd_output = $cs->cmd( 'noshut' );
print @cmd_output;

$counter = 0;
return $counter;

$cs->close;

}

can anyone see the issue here?

3 replies

by jay eckles

I'm not familiar with the Net::Telnet::Cisco package, and you didn't say exactly what "big issue" the package is giving you. However, I do see two things off the bat that might give you trouble:

1. if ($counter = 3) should most likely be if ($counter == 3). You're assigning the value 3 to $counter in the first statement, then evaluating the result of the assignment as true or false...it will always be true. The second statement compares the value of $counter to the value 3.

2. You havea function &noshut(). You call the function with an argument &noshut($counter), but the function never uses the argument. Also, the function returns a value, but you never assign the return value to any variable.

Maybe one of these two things is giving you the trouble you describe. Even if they aren't the main cause of your trouble, you'll still have to fix them eventually.

Good luck.

Jay
www.jayeckles.com

This discussion is closed to new replies.