#!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;
####
C:\Users\ImJustAFriend\Documents\Perl>LDAP-Config.pl
DEBUG: $out = Term type is now linux
script1.pl
application
script2.pl
file1.tar
backup1.tar
backup2.tar
backup3.tar
pinglist
Found "tar" files in $out...
DEBUG: $out = ifcfg-if01
ifcfg-if02
ifcfg-if03
ifcfg-if04
ifcfg-if05
ifcfg-if06
ifcfg-if07
ifcfg-if08
ifcfg-if09
ifcfg-if10
ifcfg-if11
ifcfg-if12
ifcfg-if13
ifcfg-if14
ifcfg-if15
ifcfg-if16
ifcfg-if17
ifcfg-if18
ifcfg-if19
ifcfg-if20
ifcfg-if21
ifcfg-if22
ifcfg-if23
ifcfg-if24
ifcfg-if25
ifcfg-if26
ifcfg-if27
ifcfg-if28
route-if29
route-if30
route-if31
Found "netba" files in $out...
####
C:\Users\ImJustAFriend\Documents\Perl>LDAP-Config.pl
DEBUG: $out = Term type is now linux
DEBUG: $out = script1.pl
application
script2.pl
file1.tar
backup1.tar
backup2.tar
backup3.tar
pinglist
ifcfg-if01
ifcfg-if02
ifcfg-if03
ifcfg-if04
ifcfg-if05
ifcfg-if06
ifcfg-if07
ifcfg-if08
ifcfg-if09
ifcfg-if10
ifcfg-if11
ifcfg-if12
ifcfg-if13
ifcfg-if14
ifcfg-if15
ifcfg-if16
ifcfg-if17
ifcfg-if18
ifcfg-if19
ifcfg-if20
ifcfg-if21
ifcfg-if22
ifcfg-if23
ifcfg-if24
ifcfg-if25
ifcfg-if26
ifcfg-if27
ifcfg-if28
route-if29
route-if30
route-if31