7 Replies Latest reply on Oct 7, 2005 4:36 AM by Steve Williams

    Perl / NSH issue trying to run sample perl script bluseradd.pl

      I'm trying to run this script on our appserver to create a user on a remote solaris client. I've tried it manually from an nsh shell in Config Manager, and also via an nsh script job, with the same result.

       

      The command I'm running from the NSH shell is:

       

      nexec -e /usr/bin/perl bluseradd.pl -H testsol1 -p welcome steve

       

      to create a user called steve with password welcome.

       

      It fails with the following error:

       

      -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

       

      Remote Hostname: testsol1

       

      NOTE: Cannot connect to host: testsol1.

       

      Skipping host.

       

       

      -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

       

      The code that produces this is:

      1. determine remote host's architecture

      #

      sub get_host_architecture {

      my ($remote_hostname) = @_;

      my $arch="";

       

       

      1. determine the architecture of the remote host

      if (!NSH::chdir("//$hostname")) {

      print "NOTE: Cannot connect to host: $hostname.\n\n";

      return;

      }

       

      All it seems to be trying to do is 'chdir //testsol1' which works fine if I type it into the same NSH window.

       

      The NSH.pm and Expect.pm are installed on the app server.

       

      Any ideas what I'm doing wrong? Thanks.

        • 1. Re: Perl / NSH issue trying to run sample perl script bluseradd.pl

          Your script doesn't seem to be referencing the right variables. You take in @_ to variable $remote_hostname, but then you reference $hostname when you try to chdir.

           

          There should probably be a foreach loop there. Something like

           

          sub get_host_architecture {

          my @remote_hostname = @_;

          my $arch="";

           

          1. determine the architecture of the remote host

           

          foreach $hostname (@remote_hostname) {

          if (!NSH::chdir("//$hostname")) {

          print "NOTE: Cannot connect to host: $hostname.\n\n";

          return;

          }

          }

          • 2. Re: Perl / NSH issue trying to run sample perl script bluseradd.pl

            Sorry, maybe I didn't explain it too well.

             

            I was just quoting the section of the script that is failing. The full script was written by BladeLogic and is in Knowledge Base/Download-Samples/Scripts/Perl and is called bluseradd.pl.

             

            I believe it contains the code you mention. It compiles/syntax checks ok, but when you run it, it fails attempting to "cd //".

             

            Its as though it's bypassing RBAC authorisation somehow?

            • 3. Re: Perl / NSH issue trying to run sample perl script bluseradd.pl

              This script is meant to be executed through Perl, wherever the NSH perl module is installed. From the original post, it looks as though you're nexecing this script against the target server. If you look at the help for the perl script, you'll see that the target hostlist is actually passed into the script, and the perl script is responsible for contacting the remote target and performing the appropriate operation. Try executing this with Perl from the app server/console, with a command such as:

               

              /usr/bin/perl bluseradd.pl <args, including target hostlist>

               

              • 4. Re: Perl / NSH issue trying to run sample perl script bluseradd.pl

                Yeah I've tried that as well (running the script manually on the apps server):

                 

                # perl bluseradd.pl -H testsol1 -p welcome steve123

                 

                -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

                 

                Remote Hostname: testsol1

                 

                NOTE: Cannot connect to host: testsol1.

                 

                Skipping host.

                 

                 

                -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

                • 5. Re: Perl / NSH issue trying to run sample perl script bluseradd.pl

                  Tim (or anyone else),

                   

                  The problem (I think) is that when I run this through CM via an NSH script job, the target hostname parameter that is passed to the perl script has a trailing space character added to it.

                   

                  It fails when it tries to do

                  if (!NSH::chdir("//$hostname")) {

                  print "NOTE: Cannot connect to host: $hostname.\n\n";

                  return;

                  }

                  The message displayed is:

                  NOTE Cannot connect to host: testsol1 .

                  .............................................................^ note the space before the dot

                   

                  I'm not sure where the space has come from, or whether chdir should ignore the space, or whether the perl script should remove it.

                   

                  Also, the script expects a list of comma separated hostnames. If you supply 2 target servers to the NSH script job, they are passed to the perl script without commas, so it takes the whole string as a single server.

                   

                  If you change the line that splits the hostnames by commas, to use space as the delimiter, both the above problems disappear.

                   

                  Message was edited by:

                  Steve Williams

                  • 6. Re: Perl / NSH issue trying to run sample perl script bluseradd.pl

                    I know this won't help much in the grand scheme, but a single line should fix it:

                     

                    $hostname =~ s/\s+//g;

                     

                    That should strip out any extraneous whitespace.

                    • 7. Re: Perl / NSH issue trying to run sample perl script bluseradd.pl

                      Thanks Michael. I did something similar I guess. I changed the line that sets up the target servers from

                       

                      @hosts = split (/,/, $hostnames);

                       

                      to

                       

                      @hosts = split (/ /, $hostnames);

                       

                      as CM doesn't comma separate the target server list (it uses a space).

                       

                      A side effect of this, is that it removes any trailing space.