Below is a script in perl what i want to do it to login to a host, run a few commands, but don't want to use mutilple ssh session, i want it to be done in one ssh session itself, it should check the OS (Linux/Solaris) and then run the commands appropriately and print the output in below format. hostname:domainname:OS Release version Right now, i am able to login to the box but am not able to collect the output, i get the output but the output comes line by line.
#!/usr/bin/perl #use strict; use warnings; # Checking details of the host. Domainname and the OS version will be +checked. my $SSH = '/usr/bin/ssh -o StrictHostKeyChecking=no' ; my $DOMAIN = '/bin/domainname'; my $LINUXOS = 'cat /etc/redhat-release'; my $UNIXOS = '/bin/uname -sr'; print "Enter the filename: "; chomp($HOSTLIST = <STDIN>); open HOSTS, $HOSTLIST or die "can't open the file: $!\n" ; foreach my $host (<HOSTS>) { chop($host); # if i do not use chop, ? comes in the ssh command. @details = qx($SSH $host $DOMAIN; $LINUXOS); print @details; }

1. Please help me to run the commands in one ssh session only, i know other way to do it by creating another script and calling it from the ssh command, but don't want like that.

2. How can i put checks while logged into the system and runnign the command, for particular system(in my case Linux/Solaris).

3. How the formatting of the output can be done, instead of it coming line by line.


In reply to Check host by singho

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.