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?

#!/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');
Any help on this is greatly appreciated!


In reply to Help migrating script from TELNET to SSH by bigrayhicks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.