9 Replies Latest reply on Jan 4, 2018 7:53 AM by Bill Robinson

    NSH Script unable to find OS Type

    vijay Chaudhery

      I am trying to get the server name and OS Type for the group of server but i am getting output for hostname but unable to get OS Type .

       

      # below is the script

       

      for server in $@

      do

      OS="$(nexec $server uname -s)"

       

      or

       

      OSTYPE="$(uname -D //${server} -s)"

       

      echo "$server :: $OSTYPE :: $OS"

      done

       

      Error in the Console logs

       

      Error 12/28/2017 15:52:20 The system cannot find the file specified.

      Error 12/28/2017 15:52:16 The system cannot find the file specified.

      Error 12/28/2017 15:52:12 The system cannot find the file specified.

      Error 12/28/2017 15:52:09 The system cannot find the file specified.

      Error 12/28/2017 15:52:06 The system cannot find the file specified.

        • 1. Re: NSH Script unable to find OS Type
          Santhosh Kurimilla

          Use nover or agentinfo command.

           

          Below uname command through nexec, requires cmd /c for Windows. But, your script is to identify the OS.

           

          nexec $server cmd /c uname

           

          Thanks,

          Santhosh Kurimilla

          BlackBerry# 7995072904

          • 2. Re: NSH Script unable to find OS Type
            Matthew Ragland

            Using cmd /c is reserved for Windows systems:

            nexec $SERVER cmd /c uname

            /bin/bash: cmd: command not found

             

             

            if you want it to work on linux systems do the following:

            nexec $SERVER sh -c "uname -s"

            Linux

            • 3. Re: NSH Script unable to find OS Type
              vijay Chaudhery

              Thanks for the reply, i tried all getting below error

               

               

              server1% OSTYPE="$(uname -D //${server} -s)"

              server1% echo $OSTYPE

              WindowsNT

              server1% nexec $server cmd /c uname

              'uname' is not recognized as an internal or external command,

              operable program or batch file.

              server1% nexec $server uname -s

              The system cannot find the file specified.

               

               

              server1% nexec $server sh -c "uname"

              The system cannot find the file specified.

               

               

              server1%

              • 4. Re: NSH Script unable to find OS Type
                Matthew Ragland

                I'm going to pretend to be Bill Robinson for a minute, and ask what exactly are you trying to accomplish here? What is your desired outcome? Why aren't you using the server property value for OS?

                • 5. Re: NSH Script unable to find OS Type
                  vijay Chaudhery

                  Hi Matthew, I am looking out to get the OS Type for my nsh script for this i tried the above option with does not work for me can you please let me know how to use the property value to get the OS type?

                  Trying with the below command but getting error

                   

                  server1% blcli_execute PropertyInstance getPropertyValue "Class://SystemObject/Server" "OS"

                  Command execution failed. com.bladelogic.om.infra.mfw.util.NotFoundException: Instance with path Class://SystemObject/Server was not found

                  • 6. Re: NSH Script unable to find OS Type
                    Matthew Ragland

                    Have you tried this:

                    • 7. Re: NSH Script unable to find OS Type
                      vijay Chaudhery

                      My apologies , i did not get how to use this parameter? i can use this type 1 script not sure how to use this with calling a group

                       

                       

                       

                      GROUP1="/Server/mygroup"

                       

                       

                      TOT_SRVS=`blcli Server listServersInGroup "$GROUP1"`

                       

                      OS=$2

                       

                       

                      for server in $TOT_SRVS

                      do

                       

                       

                      #OS="$(nexec $server uname -s)"

                       

                       

                      echo $OS

                      echo "servername :$server and OS Type : $OS" >> $output_file

                       

                       

                      done

                      • 8. Re: NSH Script unable to find OS Type
                        Bill Robinson

                        GROUP1="/Server/mygroup"

                        TOT_SRVS=`blcli Server listServersInGroup "$GROUP1"`

                        OS=$2

                        for server in $TOT_SRVS

                        do

                        #OS="$(nexec $server uname -s)"

                        echo $OS

                        echo "servername :$server and OS Type : $OS" >> $output_file

                        done

                        so that's kind of ok but there are some problems w/ it.

                         

                        first - why are you doing this ?  why do you need to write the server:os to a file?  what are you going to do w/ that ?

                         

                        so let's fix your script snippet above:

                        # unless you have a top level folder in the Servers workspace named 'Server' you don't include '/Server' in the group path.

                        GROUP1="/mygroup"

                        # why are you taking OS as an argument if that's what you are trying to derrive ?  so we'll take that out.

                        # you are not using the blcli very well here

                        blcli_execute Server listServersInGroup "${GROUP1}"

                        blcli_storeenv TOT_SRVS

                        # it's better habbit to use a while loop instead of a 'for' so you can handle spaces, etc. 

                        while read server

                        do

                        # why did you comment out the uname call ? 

                        OS="$(uname -D //${server} -s)"

                        echo "servername: ${server} and OS Type: ${OS}" >> "${output_file}"

                        # strip the trailing empty line from the list of servers

                        done <<< "$(awk 'NF' <<< "${TOT_SRVS}")"

                         

                         

                         

                        matt's example is using a job to pass in the server name and the value of the server property.  that works if you are running this as a nsh job.  it's unclear if you are doing that or running this as a script from the command line.  instead of the uname call you could also run a blcli command to get the value of 'OS'.  that has the advantage of not needing nsh access to the targets.  if you are running this from the command line on some workstation that may be a problem.  this version of the script would look like:

                         

                        GROUP1="/mygroup"

                        blcli_execute Server listServersInGroup "${GROUP1}"

                        blcli_storeenv TOT_SRVS

                        while read server

                        do

                        blcli_execute Server printPropertyValue ${server} "OS"

                        blcli_storeenv OS

                        echo "servername: ${server} and OS Type: ${OS}" >> "${output_file}"

                        done <<< "$(awk 'NF' <<< "${TOT_SRVS}")"

                         

                        now, that could be slow depending if you have a lot of servers in the group.  so instead you could use a bulk dump of the property value:

                        GROUP1="/mygroup"

                        blcli_execute Server listServersInGroup "${GROUP1}"

                        blcli_storeenv TOT_SRVS

                        awk 'NF {print $1",OS"}' <<< "${TOT_SRVS}" > "/tmp/get.csv"

                        blcli_execute Server getBulkServerPropertyValuesAndLogResults "/tmp" "get.csv"

                        # results will be in /tmp/get_results.csv

                        • 9. Re: NSH Script unable to find OS Type
                          Bill Robinson

                          uname is not a native windows command so your 'nexec cmd /c uname' won't work.