Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net::Telnet the right way to use??

Status
Not open for further replies.

InDenial

Technical User
Aug 1, 2003
191
NL
Hi all,

Due to some testing on a live network... (stupid I know) I found a bug in a particular switch we have...(It probably needs a reset I just am not able to save the config anymore) I am not sure if it is because of my script or just the commands I send to the switch but because of it I started to wonder about something.

When you write a script to do something on more than one switch. Would you do it like this:

Code:
use Net::Telnet()
foreach ($key, $value) = each(%hash){
   $t->new Net::Telnet()
     $t->open($key);
     $t->login("user","name");
     @lines = $t->cmd("show sys info");
     print @lines;
   $t->close;
}

OR
Code:
use Net::Telnet();
$t->new Net::Telnet();
  foreach ($key, $value) = each(%hash){
    $t->open($key);
    $t->login("user","name");
    @lines = $t->cmd("show sys info");
    print @lines;
  }
$t->close;

InDenial

 
hmm just noticed that the $t->close; should be within the foreach loop in the last example...

InDenial

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top