Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by bluethundr (Pilgrim)
on Jun 09, 2010 at 03:54 UTC ( #843800=note: print w/ replies, xml ) Need Help??


in reply to Re: Net::SSH::Perl doesn't execute commands
in thread Net::SSH::Perl doesn't execute commands

Ok then! Thanks for the very valuable input!

Ok, so I am able to issue commands to the load balancer software (which is a proprietary software layer sitting on top of a BSD core) via ssh and this is what I get:

[bluethundr@cc90-45:~ ] #:ssh bluethundr@10.50.0.1 show lb vserver gl- +www Password: Done gl-www (0.0.0.0:0) - HTTP Type: ADDRESS State: UP Effective State: UP ARP:DISABLED Client Idle Timeout: 180 sec Down state flush: ENABLED Port Rewrite : DISABLED Configured Method: ROUNDROBIN Mode: IP Persistence: NONE Redirect URL: http://pi.glcdn.us/DowntimeGeneric/gl_downtime.html Vserver IP and Port insertion: OFF 1) cc61-35-http (10.50.35.61: 80) - HTTP State: UP Weight: 1 2) cc61-44-http (10.50.44.61: 80) - HTTP State: UP Weight: 1 Done


So something like this would be the desired output of my little script.

But when I run my script the output would indicate that it's not finding the netscaler commands:

**********LB VSERVERS********** show lb vserver default-router Can't exec "show": No such file or directory at ./vservers.pl line 23, + <LBVSERVERS> line 1. Out = Done ERROR: No such command , Error = ERROR: No such command, Exit = 64 Ready for next lb vserver? (y/n): y show lb vserver gl-www Can't exec "show": No such file or directory at ./vservers.pl line 23, + <LBVSERVERS> line 2. Out = Done ERROR: No such command , Error = ERROR: No such command, Exit = 64 Ready for next lb vserver? (y/n): y show lb vserver c9-qa-bp-http Can't exec "show": No such file or directory at ./vservers.pl line 23, + <LBVSERVERS> line 3. Out = Done ERROR: No such command , Error = ERROR: No such command, Exit = 64 Ready for next lb vserver? (y/n):


And when I execute a unix shell and do a find on the "show" command it turns up nothing, nada:

root@ns# find / -name show -print root@ns#


So my question would be, why does plain old ssh find the netscaler commands when I issue them on the command line, but Net::SSH::Perl does not find them when issued from my script? Also it should be noted that I changed the quote (") marks to backticks (`) in the Net::SSH::Perl commands.

i..e.
was
$ssh->cmd("show lb vserver $csvserver");
changed to

$ssh->cmd(`show lb vserver $csvserver`);

Right now I only have output for the latter and not the former. I can get you the other input (with the quotes) if you feel it's important. Rather late, and retiring right now and picking this up again tomorrow. Thanks for your help!


Comment on Re^2: Net::SSH::Perl doesn't execute commands
Select or Download Code
Re^3: Net::SSH::Perl doesn't execute commands
by rjt (Deacon) on Jun 09, 2010 at 04:13 UTC
            $ssh->cmd(`show lb vserver $csvserver`);

    That is almost certainly not what you want to do. Your qx// example will run your "show lb ..." command on the local machine and attempt to run the output of that on the remote machine.

    It sounds like the root issue of your problem is the "show" command. I would log on to the BSD machine and run "which show" for starters--it may be an alias, or, it might be a builtin of a particular shell on the system that doesn't happen to be the same as the shell for the "bluethundr" user you're logging in with with Net::SSH::Perl.

    That being said, diagnostics are everything. I would also debug Net::SSH::Perl as well, by substituting a well-known command in place of "show". I typically start with something like this:

    #$ssh->cmd("show lb vserver $csvserver"); my ($out, $err, $exit) = $ssh->cmd("echo show lb vserver $csvserver"); + # DEBUG warn "out = '$out', err = '$err', exit = $exit\n";

    Which SSH protocol version are you using? You should be using v2. v1 does not support multiple commands per session.

Re^3: Net::SSH::Perl doesn't execute commands
by Khen1950fx (Canon) on Jun 09, 2010 at 04:42 UTC
    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;
      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 nssavecore.sh aaa_inform_kern nscgdb nssh api nscli nssslgen aslearn nsconf nsstart.sh aslearn.conf nsconfig nsstartpe.sh bgpd nsconfigaudit nsstop.sh filterwsdl nsconfmig nssync htmlinjection nsconmsg nssync.sh icsearch.sh nscrlrefresh nstcpdump.sh icstats nsdiskspace.sh nstrace.sh imi nsdme nstune imish nsdrevent nsumon.sh install.pl nsdynrouting nsumond lmgrd nsfsyncd nsvpnd lmstat nsgslbconf nswsrun lmutil nsif ospfd lmver nslcd pitboss man nslcdinit.sh portal migrate_ZebOS.sh nslog.sh ripd netscaler.conf nsm rwpol netscaler.sh nsmap samedit ns_gui nsnetsvc showtechsupport.pl nsaaad nsospf snmp nsapimgr nsp snmpd nsaudit nsproflog.sh vpnsetup nsauth_httpd nsprofmon vtysh nsauthd nsreadfile nsbgp nsrip

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://843800]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2014-09-20 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (163 votes), past polls