Hi Experts,
I am using following format for Perl SSH2 commands.
HTML Code:
#!/usr/bin/perl -w
use Net::SSH::Perl;
use POSIX;
use Sys::Hostname;
use Term::ANSIColor qw(:constants);
use strict;
#my $host="10.128.0.214";
my @nodeip = ("10.128.0.214","10.128.0.215") ;
my %node = ("10.128.0.214","NODE-HOST1","10.128.0.215","NODE-HOST2") ;
my $hlckdate = strftime "%Y-%m-%d",localtime ;
my $user="user" ;
my $pass="passwd";
my $cmd ="uname -a";
my $host = hostname;
foreach (@nodeip) {
my $ssh = Net::SSH::Perl->new($_,protocol =>'2',port =>22 );
$ssh->login($user, $pass);
$ssh->register_handler("stdout",sub {my ($channel,$buffer) = @_; print $buffer->bytes;});
print "\n\n==========================================================================================\n";
print " PERFORMING CHECK FOR $node{$_} \@ $hlckdate \n";
print "==========================================================================================\n";
print BOLD,"OS INFO: ", RESET;
$ssh->cmd($cmd);
print BOLD,"\nSYS UPTIME: ",RESET;
$ssh->cmd('uptime');
print BOLD,"\nSYS RUN LEVEL:",RESET;
$ssh->cmd('who -r');
print BOLD,"\nFILESYSTEM INFO:\n",RESET;
$ssh->cmd('df -h');
Output is as expected:
HTML Code:
==========================================================================================
PERFORMING CHECK FOR NODE-HOST2 @ 2010-11-21
==========================================================================================
OS INFO: Linux host2 2.4.21-40.ELsmp #1 SMP Thu Feb 2 22:22:39 EST 2006 i686 i686 i386 GNU/Linux
SYS UPTIME: 16:08:01 up 219 days, 19:51, 1 user, load average: 0.06, 0.06, 0.02
SYS RUN LEVEL: run-level 3 Dec 4 16:52 last=S
FILESYSTEM INFO:
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 985M 233M 702M 25% /
/dev/cciss/c0d0p1 97M 26M 67M 28% /boot
/dev/vg00/home 4.9G 1.5G 3.2G 32% /home
/dev/vg00/log 2.9G 1.7G 1.2G 60% /log
/dev/vg00/opt 5.8G 950M 4.6G 17% /opt
none 2.5G 0 2.5G 0% /dev/shm
/dev/vg00/tmp 2.9G 41M 2.7G 2% /tmp
/dev/vg00/usr 5.8G 3.0G 2.6G 54% /usr
/dev/vg00/var 2.0G 418M 1.5G 23% /var
I have been trying to collect output of command in an array to process content.
If i can do something like
HTML Code:
my @tmpout = "output from previous command ( say df -h )"
foreach (@tmpout){
..
}
I have been searching a lot but no success till now.
Any help and hints?
Thanks in advance.
---------- Post updated at 01:50 PM ---------- Previous update was at 08:19 AM ----------
I have made this small change
HTML Code:
$ssh->register_handler("stdout",sub {my ($channel,$buffer) = @_; my $output = $buffer->bytes;});
Expecting normal usage, I made following changes:
HTML Code:
print BOLD,"OS INFO: ", RESET;
$ssh->cmd($cmd);
print $output ;
#OR
my @out2 = print $output;
I am getting following error for each line where i am using $output.
HTML Code:
Global symbol "$output" requires explicit package name at ./scriptname.pl line XX
Any Clues ??