Net::SSH::Perl ...... how to print the output in a proper format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Net::SSH::Perl ...... how to print the output in a proper format
# 1  
Old 04-27-2009
Net::SSH::Perl ...... how to print the output in a proper format

Hi Guys,

my $cmd = "ls -l"; #........ {or let it be as # my $cmd= "ls"; }
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($user, $pass);
my($stdout, $stderr, $exit) = $ssh->cmd("$cmd");
print $stdout;

the script works fine, but i am unable to see the output getting displayed in a correct format.
i.e output of the above script is as follows:

total 79936 -rw-r--r-- 1 readonly bin 306 Feb 13 2008 a1.sh -rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog1.sh -rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog2.sh -rw-r--r-- 1 readonly bin 1248 Feb 13 2008 ca.log -rw-r--r-- 1 readonly bin 38143 Jul 17 2008 17072008_Run2 drwxr-xr-x 2 readonly bin 4096 Apr 9 2008 s -rw-r--r-- 1 readonly bin 14739 Jul 17 2008 07172008_Run2 -rw-r--r-- 1 readonly bin 15152 Jul 16 2008 17_07_2008


Instead of displaying the output as,

total 79936
-rw-r--r-- 1 readonly bin 306 Feb 13 2008 a1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog2.sh
-rw-r--r-- 1 readonly bin 1248 Feb 13 2008 ca.log
drwxr-xr-x 2 readonly bin 4096 Apr 9 2008 s
-rw-r--r-- 1 readonly bin 14739 Jul 17 2008 Analysis_07172008_Run2
-rw-r--r-- 1 readonly bin 15152 Jul 16 2008 17_07_2008


Please anyone let me know your valuable suggestions to display the o/p as
total 79936
-rw-r--r-- 1 readonly bin 306 Feb 13 2008 a1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog2.sh
-rw-r--r-- 1 readonly bin 1248 Feb 13 2008 ca.log
drwxr-xr-x 2 readonly bin 4096 Apr 9 2008 s
-rw-r--r-- 1 readonly bin 14739 Jul 17 2008 Analysis_07172008_Run2
-rw-r--r-- 1 readonly bin 15152 Jul 16 2008 17_07_2008


Not only for 'ls' command, but executing any commands using Net::SSH::Perl connection displays the output as a single line.

Please let me know your valuable suggestions.

Thanks in Advance
# 2  
Old 04-27-2009
In the future, please use [code ][/code ] tags, it improves readability.

What's the output if you change the last line to print ref($stdout)? Maybe it doesn't return a string but an array of strings.
# 3  
Old 04-27-2009
As i tried replacing last line with print ref($stdout); displays a blank output (i.e no output)
# 4  
Old 04-27-2009
Also if i replace last two lines of code as ,
my(@stdout, $stderr, $exit) = $ssh->cmd("$cmd");
print @stdout;

i see no difference between $stdout & @stdout outputs.
# 5  
Old 04-27-2009
If ref() returns an empty string that means that it isn't a reference to anything. And assigning a scalar to an array just makes that scalar the first element of the array.

I guess that the newline gets lost somewhere during transfer (either dropped by the server or Net::SSH::Perl itself) since in the code they're only appending one line of returned data to the previous lines, returning all of it in $stdout/$stderr.
# 6  
Old 04-27-2009
Yes, you are right which is expected.

But i am looking for some way/solution where we can print the output as if executing a command in a unix box displays the output in a clear format. At present i am using CGIPerl Script to display the output on a browser and i am able to print the output on a browser in this way ....

total 79936 -rw-r--r-- 1 readonly bin 306 Feb 13 2008 a1.sh -rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog1.sh -rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog2.sh -rw-r--r-- 1 readonly bin 1248 Feb 13 2008 ca.log -rw-r--r-- 1

Last edited by gsprasanna; 04-27-2009 at 10:25 AM..
# 7  
Old 04-27-2009
Though at present i am having a solution where we can split the output of 'ls' command as the output will be of this format ...

-rw-rw-rw- 1 root dir 104 Dec 25 19:32 filename

we can split the above output as fields i.e at filename field and we can assign this to an array and there by we can print the output.
i.e
total 79936
-rw-r--r-- 1 readonly bin 306 Feb 13 2008 a1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog2.sh
-rw-r--r-- 1 readonly bin 1248 Feb 13 2008 ca.log
drwxr-xr-x 2 readonly bin 4096 Apr 9 2008 s


But this is just a temporary solution which works fine for 'ls -l' command. But tomorrow if we wish to execute other commands such as "ls", "cat" and so on... it wont work.

But i appreciate 4ur thoughts & ur precious time.....
Still lets hope for a solution where we can print the output in a format wrapped at every newline of output and display the same on a browser.

Thanks in Advance,
GS
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert rows to column and print output in required format

Hi All, i am trying to print the solaris 11 packages in below required format, But i am unable to do that. Current ouput : root@abc# pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' NAME: QLogic 570x/571x Gigabit Ethernet Driver VERSION: 11.11,REV=2009.11.11 ... (7 Replies)
Discussion started by: balu1234
7 Replies

2. Shell Programming and Scripting

Combine multiline to one line with proper format

Hello Guys, I have a file say FILE1.txt contains below data:- A B C D E F G H I J K L I need the output in another file as FILE2 as:- 'A', 'B', 'C', 'D', 'E', (7 Replies)
Discussion started by: jassi10781
7 Replies

3. Shell Programming and Scripting

Read from text file;format and print output

Hi Following is the assumed input... Symmetrix ID : 12345 Originator Port wwn : 123456789 User-generated Name : 123456789/123456789 Sym Dev Dir:P LUN ------ ----- ----------------------- ---- --- ---- ---- ---- ------- 1234 ... (4 Replies)
Discussion started by: maddy.san
4 Replies

4. Shell Programming and Scripting

how to format ssh top output

Hello; Am trying to generate runaway proc report using ssh thusly: =================== ssh -t -t $BOX 'TERMINAL="vt100" top -d1 -h -n 10' >> $FILE . . cat $FILE | mail -s "Latest Top `date`" $MAIL_TO ==================== But the output to e-mail comes out rather garbled .. Any ideas... (1 Reply)
Discussion started by: delphys
1 Replies

5. Shell Programming and Scripting

Need to split a xml file in proper format

Hi, I have a file which has xml data but all in single line Ex - <?xml version="1.0"?><User><Name>Robert</Name><Location>California</Location><Occupation>Programmer</Occupation></User> I want to split the data in proper xml format Ex- <?xml version="1.0"?> <User> <Name>Robert</Name>... (6 Replies)
Discussion started by: avishek007
6 Replies

6. Shell Programming and Scripting

Net::SSH::Perl slow to login.

I have some sample code that's supposed to ssh to another machine using Net::SSH::Perl, execute a command, and print the output of that command. It's very basic, and it works. However, I noticed that upon logging in: $ssh->login('username','password'); It takes roughly 10-13 seconds to... (2 Replies)
Discussion started by: mrwatkin
2 Replies

7. Shell Programming and Scripting

Getting Proper Date Format in SH Script

There's a small SH script I'm trying to write where it will get the current month and find a log file that is based on the date. Example: Today is February, so the log file is going to be 201102.log (2011 + 02) An additional thing is that if today is the 1st of a month, it will also find the log... (3 Replies)
Discussion started by: kooshi
3 Replies

8. Shell Programming and Scripting

Output file not displayed in the proper format

Hi am using uuencode fro attaching one report which is nothing but sql query output. But when i receive the report through attachement and when it is opened the report is not displayed in proper format. Means if the sql query has 100 rows the mail attachment report displays the report in 2... (2 Replies)
Discussion started by: weknowd
2 Replies

9. Shell Programming and Scripting

Net::SSH::Perl->Execute any unix command & display the output in a proper form

Net::SSH::Perl ...... how to print the output in a proper format my $cmd = "ls -l"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output... (2 Replies)
Discussion started by: gsprasanna
2 Replies

10. Shell Programming and Scripting

Check for proper e mail id format

Hi, We run an application called meta which reads user information from database and updates in LDAP.For that we have some scripts to check the uniqueness of mail ids between the existing LDAP and Database.It works fine when people enter mail ids in proper format (xxx.yyy@abc.com) but if it... (2 Replies)
Discussion started by: prolay
2 Replies
Login or Register to Ask a Question