perl ssh2 output formatting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl ssh2 output formatting
# 8  
Old 11-30-2010
Alright folks.. i had a small lead with the code and i was able to make necessary decisions by choosing option of exit status of previous command as my test and thus requirement to call rest of the script was completed. However I am left with few questions.

Here is my code.
Code:
#!/usr/bin/perl -w

use Net::SSH::Perl;
use POSIX;

use Term::ANSIColor qw(:constants);
use strict;

my $host="10.0.0.1";
my $user="usr";
my $pass="passwd";
my $cmd ="uname -a";

my $stdout;
my $stderr;
my $stdexit;


    my $ssh = Net::SSH::Perl->new($host,protocol =>'2',port =>22 );
    $ssh->login($user, $pass);
    $ssh->register_handler("stdout",sub {my ($channel,$buffer) = @_; print $buffer->bytes;
        });
    
    print BOLD,"OS INFO: ", RESET;
    $ssh->cmd($cmd);
    print BOLD,"\nFILESYSTEM INFO:\n",RESET;
    $ssh->cmd('df -h');
    
    ($stdout,$stderr,$stdexit) = $ssh->cmd('ifconfig -a | grep 192.168.35.216');
    
print $stdexit;

Now it gives me perfect output and a nice $stdexit value to compare and run rest part of my script on correct server.

But problem i began with remained same. I was still not able to print $stdout and $strerr while $stdexit coming nice.
Code:
Use of uninitialized value $stdout in print at ./perl_ssh.pl line 29.
Use of uninitialized value $stderr in print at ./perl_ssh.pl line 30.

I even tried changing names to $stdout_a , $stdout_b but no luck.
My problem is solved but i am left with confusion of ssh2 perl module.
Anyways .. may be all this text will be helpful to someone ...
Smilie

.

Last edited by mtomar; 11-30-2010 at 12:30 PM.. Reason: minor code change
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question