#!C:/Perl/bin/perl.exe use strict; use warnings; use Net::SSH2; my $BE_conn; my $BE_ip; my $BE_chan; my $out; $BE_ip="nnn.n.nn.nnn"; $BE_conn = Net::SSH2->new(); $BE_conn->debug(0); $BE_conn->connect($BE_ip) or die "BE_conn: $!\n"; $BE_conn->auth_password('user','pass') or die "Unable to login to BE\n"; $BE_chan = $BE_conn->channel(); $BE_chan->blocking(0); $BE_chan->shell(); #Next 2 lines needed or $BE_chan only gets "Term type is now linux" #Note that NOTHING prints preceded by "CHAN LINE" to my window print $BE_chan "\nwho am i\n"; print "CHAN LINE: $_" while <$BE_chan>; #Run a simple command, test process the output with regex print $BE_chan "\nls /u/ainet\n"; while ( <$BE_chan> ) { $out .= $_; } print "DEBUG: \$out = $out\n"; if ( $out =~ m/^.*tar.*$/m ) { print "Found \"tar\" files in \$out...\n"; } $out = ""; #Run second simple command to ensure $out works still print $BE_chan "\nls /opt/config/servers/0-0-1/local/root/etc/sysconfig/network-scripts\n"; while ( <$BE_chan> ) { $out .= $_; } print "DEBUG: \$out = $out\n"; if ( $out =~ m/^.*netba.*$/m ) { print "Found \"netba\" files in \$out...\n"; } $out = ""; #Run a script, capture the output, regex it #print $BE_chan "\n/u/ainet/BatchPing.pl pinglist tcp\n"; #while ( <$BE_chan> ) { $out .= $_; } #print "DEBUG: \$out = $out\n"; #if ( $out =~ m/^.*NOT.*$/m ) { # print "Found \"NOT\" lines in \$out...\n"; #} #$out = ""; $BE_chan->close;