Sponsored Content
Full Discussion: perl ssh2 output formatting
Top Forums Shell Programming and Scripting perl ssh2 output formatting Post 302474531 by mtomar on Wednesday 24th of November 2010 12:51:13 PM
Old 11-24-2010
Code:
#!/usr/bin/perl -w
use Net::SSH::Perl;
#use Net::SSH::Perl::Buffer (my @args);
use POSIX;
use Sys::Hostname;
use Term::ANSIColor qw(:constants);
use strict;

my $tmpout="";
#my $host="192.168.35.214";
my @nodeip = ("192.168.35.214","192.168.35.215") ;
my %node = ("192.168.35.214","NODE-HOST1","192.168.35.215","NODE-HOST2") ;
my $hlckdate = strftime "%Y-%m-%d",localtime ;
my $user="user" ;
my $pass="passwd";
my $cmd ="uname -a";
my $host = hostname;
#my $buffer = Net::SSH::Perl::Buffer->new;

foreach (@nodeip) {
    my $ssh = Net::SSH::Perl->new($_,protocol =>'2',port =>22,#debug => 1
    );
    $ssh->login($user, $pass);
    $ssh->register_handler("stdout",sub {my ($channel,$buffer) = @_; $tmpout = print $buffer->bytes;});
    #$ssh->register_handler("stdout",sub {my ($channel,$buffer) = @_; print $buffer->get_str;});
    
    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');
    print "\n\n CHECKING IF CURRENT SERVER IS ACTIVE ..............\n\n";
    $ssh->cmd('ifconfig -a | grep 192.168.35.216');
    print $tmpout;
    my @chksys = $tmpout;
    print @chksys ;
    print @chksys ;
        foreach (@chksys){
                             if(/192.168.35.216/){
                         print "----------------------------------------------------------------\n";
                         print "$host is active server.....performing other checks....\n";
                         print "----------------------------------------------------------------\n\n";
                         $ssh->cmd('ps -ef | grep manager');
                         #my nodeinfo1 = print @tmpout ;
                         print "----------------------------------\n";
                         print "NODE SERVICE:";
                         print "----------------------------------\n\n";
                         #foreach(@nodeinfo1){
                             #if(/grep/){    
                             #}else{
                             #    print $_;
                             #}
                        }
                      }
                    }

OUTPUT
Code:
==========================================================================================
            PERFORMING CHECK FOR NODE-HOST1 @ 2010-11-24    
==========================================================================================
OS INFO: Linux host1 2.4.21-40.ELsmp #1 SMP Thu Feb 2 22:22:39 EST 2006 i686 i686 i386 GNU/Linux

SYS UPTIME:  20:46:33  up 13 days,  8:14,  0 users,  load average: 0.00, 0.01, 0.00

SYS RUN LEVEL:         run-level 3  Nov 11 12:32                   last=S  

FILESYSTEM INFO:
Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p2     985M  273M  663M  30% /
/dev/cciss/c0d0p1      97M   26M   67M  28% /boot
/dev/vg00/home        4.9G  3.2G  1.5G  69% /home
/dev/vg00/informix    985M  469M  466M  51% /informix
/dev/vg00/log         2.9G  779M  2.0G  28% /log
/dev/vg00/opt         5.8G  993M  4.6G  18% /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.5G  55% /usr
/dev/vg00/var         2.0G  625M  1.3G  34% /var


 CHECKING IF CURRENT SERVER IS ACTIVE ..............

111

==========================================================================================
            PERFORMING CHECK FOR NODE-HOST2 @ 2010-11-24    
==========================================================================================
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:  20:46:53  up 223 days, 30 min,  0 users,  load average: 0.05, 0.08, 0.03

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/informix    985M  323M  612M  35% /informix
/dev/vg00/log         2.9G  1.9G  896M  69% /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  434M  1.5G  24% /var
/dev/vgraid/cdr       2.0G   33M  1.9G   2% /cdr
/dev/vgraid/prompts   2.0G   97M  1.8G   6% /prompts
/dev/vgraid/archive    20G   13G  6.5G  66% /archive
/dev/vgraid/ready     2.0G   34M  1.9G   2% /ready
/dev/vgraid/data      9.9G  2.0G  7.5G  21% /data
/dev/vgraid/mcx       9.9G  3.5G  6.0G  37% /mcx


 CHECKING IF CURRENT SERVER IS ACTIVE ..............

          inet addr:192.168.35.216  Bcast:192.168.35.255  Mask:255.255.255.0
111

See 111 at the end of output. It is because of
Code:
print $tmpout;
    my @chksys = $tmpout;
    print @chksys ;
    print @chksys ;

While i am expecting
Code:
inet addr:192.168.35.216  Bcast:192.168.35.255  Mask:255.255.255.0

print is just for check. As you can see in code above i want to run some commands if string have 192.168.35.216 in it.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

formatting output

Hi need some advice.. #grep -i hostname test.csv (gives the below output) HOSTNAME,name,host_test,,,,,,,, Now I need to format the above output as below. HOSTNAME: name=host_test Any easy way of doing this using awk or sed or printf? (4 Replies)
Discussion started by: balaji_prk
4 Replies

2. Shell Programming and Scripting

Formatting Output

Hi I tried running the below awk 'BEGIN { printf ("%s %-51s %s %-7s %s",$var1,$var2,$var3,$var4,$var5)}' from the command prompt and it is not working. Getting the error awk: Field $() is not correct. The source line number is 1. Actually my requirement is to form a string based on... (6 Replies)
Discussion started by: dhanamurthy
6 Replies

3. Shell Programming and Scripting

formatting the output

Is it possible to convert the attached file to the format mentioned. Here for a particular job the table name and the corresponding instance name from one test run "X" is compared with the table name and the instance name from the second test run "Y" for output rows,affected rows,applied... (1 Reply)
Discussion started by: ragavhere
1 Replies

4. Shell Programming and Scripting

Formatting ls output

I am using find and ls to search for "warez" files on my server. find /home/ -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\)" -print0 | xargs -0 ls -oh This command produces this: -rw-r--r-- 1 1000 3.2M Feb 18 2009 /home/user/public_html/lupus.mp3 I want to only get this 3.2M... (4 Replies)
Discussion started by: bonrad
4 Replies

5. Shell Programming and Scripting

Formatting my output

Dear All, I am new to unix scripting. I need your help to format my output on screen. echo " --------------------------------------------" echo " | My Output |" echo " --------------------------------------------" echo " | A: $A... (5 Replies)
Discussion started by: rahiljavaid
5 Replies

6. Shell Programming and Scripting

Formatting Perl Output

Hi, I am getting the output from a PERL program but the output is all on different lines. My code is printf hOUT "%s\t%s\t%s\t%s\t%s\t%s",$M1_CTR, $M2_CTR, $M3_CTR, $M4_CTR, $M5_CTR, $M6_CTR; Example: My report (which I send via email) should look like this Area 1 Area 2 ... (4 Replies)
Discussion started by: nurani
4 Replies

7. Shell Programming and Scripting

Perl ssh2 login issue.

Hi Experts, I came across this interesting situation. I have following ssh script login to multiple server. This works fine for one set of servers (linux) but on my sun boxes i am getting. error #!/usr/bin/perl -w use Net::SSH::Perl; use POSIX; use Term::ANSIColor qw(:constants); use... (2 Replies)
Discussion started by: mtomar
2 Replies

8. Shell Programming and Scripting

Formatting the output

Hi, I have a file which contents entries in this form. Only in /data4/temp abc.000001 Only in /data4/temp abc.000003 Only in /data4/temp abc.000012 Only in /data4/temp abc.000120 Only in /data4/temp abc.000133 Only in /data4/temp abc.001444 i want to read line by line and format... (2 Replies)
Discussion started by: arijitsaha
2 Replies

9. Shell Programming and Scripting

Formatting output

I have the output like below: DEV#: 9 DEVICE NAME: hdisk9 TYPE: 1750500 ALGORITHM: Load Balance SERIAL: 68173531021 ========================================================================== Path# Adapter/Path Name State Mode Select Errors 0 ... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

10. Shell Programming and Scripting

Formatting of output

Hi, I have some output in the format below: Col-A Col-B 8781 4319 8781 2332 8781 0269 5550 3282 5550 9465 5550 7607 7064 4456 . . I want to re-format the output so i will get something like this: 8781:4319,2332,0269 5550:3282,9465,7607 7064:4456 for... (6 Replies)
Discussion started by: james2009
6 Replies
All times are GMT -4. The time now is 05:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy