bigrayhicks has asked for the wisdom of the Perl Monks concerning the following question:
Hello.. I am new to this board and it has been some time since i have worked writing PERL. I have been asked to take a look at the attached script and see if I can get it changed from using TELNET to using SSH. I wonder if it is as simple as changing the module from NET::TELNET to NET::SSH. Any advice?
Any help on this is greatly appreciated!#!/usr/bin/perl use Net::Telnet; use strict; #********************** User defined variables *********************** +************** my $username='adminuser'; my $password='xxxxxxxxx'; my $machine='192.168.102.21'; #********************************************************************* +************** #Open telnet session to host my $telnet = new Net::Telnet ( Timeout=>30, Errmode=>'die', Input_log +=> 'logs\\telnet-remove-exclusions-log-WLC02.txt'); $telnet->open($machine); $telnet->waitfor('/User: $/i'); $telnet->print($username); $telnet->waitfor('/Password:$/i'); $telnet->print($password); $telnet->waitfor('/\(Cisco Controller\) >$/i'); #check for error status which should be undefined my $msg = $telnet->errmsg; print "$msg\n"; #loop while the command does not timeout looking for a different promp +t while (not $msg) { my @output = $telnet->cmd(String => 'show exclusionlist', Prompt => +'/Would you like to display the next 15 entries?/', errmode => 'retur +n'); $msg = $telnet->errmsg; $telnet->print('N'); print @output; foreach my $mac (@output) { if ($mac =~ m/([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\ +:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})/) { my $cmd = "config exclusionlist delete " . $mac; $telnet->cmd(String => $cmd, Prompt => '/\(Cisco Controller\) >$ +/i'); } } } #once command times out looking for the continue prompt, run it one mo +re time with the regular prompt my @output = $telnet->cmd(String => 'show exclusionlist', Prompt => '/ +\(Cisco Controller\) >$/i', errmode => 'return'); print @output; foreach my $mac (@output) { if ($mac =~ m/([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\ +:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})/) { my $cmd = "config exclusionlist delete " . $mac; $telnet->cmd(String => $cmd, Prompt => '/\(Cisco Controller\) >$ +/i'); } } $telnet->print('logout');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help migrating script from TELNET to SSH
by zentara (Cardinal) on Sep 21, 2011 at 18:03 UTC | |
by salva (Canon) on Sep 21, 2011 at 18:30 UTC | |
by zengargoyle (Deacon) on Sep 22, 2011 at 08:34 UTC | |
by salva (Canon) on Sep 22, 2011 at 09:02 UTC | |
by zengargoyle (Deacon) on Sep 23, 2011 at 11:37 UTC | |
|
Re: Help migrating script from TELNET to SSH
by MidLifeXis (Monsignor) on Sep 21, 2011 at 16:51 UTC | |
|
Re: Help migrating script from TELNET to SSH
by salva (Canon) on Sep 23, 2011 at 08:47 UTC |