Greetings Monks, I am having a hard time tracking down this issue I am having with the Net::SSH2 module. Basically, my code will read in a file containing information to be programmed into a menu-driven network device. The code will iterate through about 21 lines before simply exiting in the middle of a print statement. I am positive it is not due to faulty file input as I can replicate the issue with any file exceeding 21 lines. I'd like to know if there is any kind of debugging I can do that will show why the program is crashing. All code is contained below:
#!/usr/bin/perl use 5.010; use strict; use warnings; use Net::SSH2; use Data::Validate::IP; #Variables my $host = $ARGV[0]; my $tacacsusername = $ARGV[1]; my $tacacspassword = $ARGV[2]; my $fh = $ARGV[3]; my $validator = Data::Validate::IP->new; if (@ARGV != 4 || !$validator->is_ipv4($host)) { print "Invalid arguments, exiting."; exit; } open(my $data, '<', $fh) or die "Could not open '$fh' $!\n"; my $ssh = Net::SSH2->new(); $ssh->connect($host, 22); $ssh->auth_password($tacacsusername, $tacacspassword); if($ssh->auth_ok) { my $channel = $ssh->channel(); $channel->blocking(0); $channel->shell(); print $channel "network\n"; #Enter network context print $channel "ddelete\n"; #Clear DAT table print $channel "yes\n"; #Confirm clearing DAT sessions print $channel "b\n"; #Return to main context print "$_" while <$channel>; #Print output to console #Iterate the CSV file line by line while (my $line = <$data>) { chomp $line; my @fields = split "," , $line; print $channel "subscribers\n"; #Enter subscriber context print $channel "add\n"; #Add subscriber print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[0]\n"; #Hostname print $channel "1\n"; # Type of Profile 1=Device print $channel "$fields[2]\n"; #IP Address print $channel "\n"; #Subnet print $channel "\n"; #User Definable 1 print $channel "\n"; #User Definable 2 print $channel "\n"; #Upstream Bandwidth in kbps print $channel "\n"; #Downstream Bandwidth in kbps print $channel "\n"; #QOS Policy print $channel "$fields[3]\n"; #VLAN print $channel "\n"; #Proxy arp print $channel "\n"; #SMTP Redirection print $channel "b\n"; #Exit subscriber context print "$_" while <$channel>; #Print output to console if(scalar(@fields) > 5 && $fields[4] ne ''){ print $channel "system\n"; #Enter system context print $channel "static\n"; #Enter static portmap context print $channel "add port\n"; #Add new portmap print $channel "$fields[2]\n"; #IP Address print $channel "$fields[4]\n"; #SNMP Internal port print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[5]\n"; #SNMP External port print $channel "UDP\n"; #UDP on first pass for SNMP print $channel "\n\n"; #Remote IP, port print $channel "enable\n"; #Use access control print $channel "b\nb\n"; #Return to main context print "$_" while <$channel>; #Print output to console } if(scalar(@fields) > 7 && $fields[6] ne ''){ print $channel "system\n"; #Enter system context print $channel "static\n"; #Enter static portmap context print $channel "add port\n"; #Add new portmap print $channel "$fields[2]\n"; #IP Address print $channel "$fields[6]\n"; #MGMT Internal port print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[7]\n"; #MGMT External port print $channel "TCP\n"; #TCP on second pass for MGMT print $channel "\n\n"; #Remote IP, port print $channel "enable\n"; #Use access control print $channel "b\nb\n"; #Return to main context print "$_" while <$channel>; #Print output to console } if(scalar(@fields) > 9 && $fields[8] ne ''){ print $channel "system\n"; #Enter system context print $channel "static\n"; #Enter static portmap context print $channel "add port\n"; #Add new portmap print $channel "$fields[2]\n"; #IP Address print $channel "$fields[8]\n"; #MGMT Internal port print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[9]\n"; #MGMT External port print $channel "TCP\n"; #TCP on second pass for MGMT print $channel "\n\n"; #Remote IP, port print $channel "enable\n"; #Use access control print $channel "b\nb\n"; #Return to main context print "$_" while <$channel>; #Print output to console } else { print $channel "b\nb\n"; #Return to main context } print "$_" while <$channel>; #Print output to console } print $channel "b\n"; print $channel "logout\n"; print "$_" while <$channel>; print "\n"; $channel->send_eof(); $channel->close(); $ssh->disconnect(); } else { print "ERROR: Please verify credentials as the connection to the +gateway failed\n"; }

In reply to Net::SSH2 limitation? by bbarrette

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.