Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: Net::SSH::Perl doesn't execute commands

by Khen1950fx (Canon)
on Jun 09, 2010 at 04:42 UTC ( #843807=note: print w/replies, xml ) Need Help??

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.
$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"); 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/'; 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
#!/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
    This is a really nice, clean version of the script. Excellent work!

    Well I have to admit that I'm really puzzled at this point! Because I cannot find "show" nowhere on this system. It only works if you 1) ssh into the box and operate within the proprietary netscaler environment or 2) if you issue the commands remotely via ssh.

    If I execute a "shell" command within the netscaler software to get to a unix shell, this is the result of my best efforts to find the command called "show".

    root@ns# find / -name "show" -print root@ns# show -bash: show: command not found root@ns# echo $PATH /netscaler:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/usr/local/bin:/ +usr/local/sbin:. root@ns# grep -ri show $PATH grep: /netscaler:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/usr/local +/bin:/usr/local/sbin:.: No such file or directory root@ns#

    What gives? I'm starting to feel like there is some voodoo going on with this box that I don't completely grok! Do I have to somehow invoke the netscaler shell first,before I do anything else?

    This is the contents of a directory called "/netscaler" that has a bunch of commands and scripts in it, that I can't seem to make heads or tails of. Most of them are binaries (not scripts) so I can't even "less" them to see what they contain. weird!
    root@ns# ls CITRIX nscachemgr aaa_inform_kern nscgdb nssh api nscli nssslgen aslearn nsconf aslearn.conf nsconfig bgpd nsconfigaudit filterwsdl nsconfmig nssync htmlinjection nsconmsg nscrlrefresh icstats imi nsdme nstune imish nsdrevent nsdynrouting nsumond lmgrd nsfsyncd nsvpnd lmstat nsgslbconf nswsrun lmutil nsif ospfd lmver nslcd pitboss man portal ripd netscaler.conf nsm rwpol nsmap samedit ns_gui nsnetsvc nsaaad nsospf snmp nsapimgr nsp snmpd nsaudit vpnsetup nsauth_httpd nsprofmon vtysh nsauthd nsreadfile nsbgp nsrip

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://843807]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-04-26 10:37 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (471 votes). Check out past polls.