in reply to Re^2: Net::SSH::Perl doesn't execute commands
in thread Net::SSH::Perl doesn't execute commands
You haven't given a valid command yet.
That's not a command that ssh will recognize.$ssh->cmd("show 1b vserver $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.$ssh->cmd("ls /path/to/csvserver");
Update: Here's the first part:
Update: Here's showthis.pl#!/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";
#!/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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Net::SSH::Perl doesn't execute commands
by bluethundr (Pilgrim) on Jun 09, 2010 at 11:14 UTC |
In Section
Seekers of Perl Wisdom