Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
You haven't given a valid command yet.
$ssh->cmd("show 1b vserver $csvserver");
That's not a command that ssh will recognize.
$ssh->cmd("ls /path/to/csvserver");
That would be a valid command because it's a "system command". I've noticed that a lot of programmers that are new to ssh make the same mistake. I would split the script in to two scripts. The first part would ssh the second part; hence, $ssh->cmd("perl showthis.pl"); would work.

Update: Here's the first part:

#!/usr/bin/perl use strict; use Net::SSH::Perl; my $host = 'localhost'; my $user = 'username'; my $pass = 'password'; my $cmd = 'perl /path/to/showthis.pl'; my $ssh = Net::SSH::Perl->new( $host, protocol => '2', debug => 1, ); $ssh->login( $user, $pass ); my ( $stdout, $stderr, $exit ) = $ssh->cmd($cmd); print "$stdout\n";
Update: Here's showthis.pl
#!/usr/bin/perl use strict; use warnings; my $dir = "$ENV{HOME}/data"; open LBVSERVERS, '<', "$dir/lb-vserver" or die "Couldn't open file: $!"; open CSVSERVERS, '<', "$dir/cs-vserver" or die "Couldn't open file: $!"; print "\n\n\n\n\n**********LB VSERVERS**********\n\n\n\n\n"; while ( my $line = <DIR> ) { chomp $line; my ( $number, $dir ) = split( /\s+/, $line ); print "show lb vserver $lbvserver\n"; print "Ready for next lb vserver? (y/n): "; chomp( my $ans = <STDIN> ); if ( $ans =~ /y|Y/ ) { next; } else { last; } } print "\n\n\n\n\n**********CS VSERVERS**********\n\n\n\n\n"; while ( my $line = <DIR> ) { chomp $line; my ( $number, $dir ) = split( /\s+/, $line ); print "show lb vserver $csvserver\n"; print "Ready for next lb vserver? (y/n): "; chomp( my $ans = <STDIN> ); if ( $ans =~ /y|Y/ ) { next; } else { last; } } print "\n\n\nEnd of line.\n\n\n"; close LBVSERVERS; close CSVSERVERS;

In reply to Re^3: Net::SSH::Perl doesn't execute commands by Khen1950fx
in thread Net::SSH::Perl doesn't execute commands by bluethundr

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (8)
    As of 2014-12-25 08:01 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (159 votes), past polls