3 Replies Latest reply on Sep 3, 2020 8:40 AM by Bill Robinson

    issues with while/for loop

    Parag Desai
      Share This:

      TSSA 8903

       

      Hi All,

           I have a script job (type2) with below while loop.

      ------------------------------------------------------------------------------------------------------------------------------

      #!/bin/nsh

      hostList=$1

       

      while read host

      do

              ServerOS=`nexec -i $host uname | cut -d'-' -f1`

              echo "Processing ${ServerOS} server with hostname - ${host}"

            

           if [[ "${ServerOS}" == "HP" ]]; then

                  nexec -i ${host} swlist -l patch -a install_date >> ${folderPath}/${folderName}/runningProcesses.txt

                      if [ -f //$host/etc/default/security ]; then

                              nexec -i ${host} 'cat /etc/default/security | egrep -v '^#'' >> ${folderPath}/${folderName}/HP_SecurityPolicies.txt

                      else

                              echo "/etc/default/security file does NOT exist on HP-UX Server -  ${host}" >> ${folderPath}/${folderName}/HP_SecurityPolicies.txt

                       fi

                

              elif [[ "${ServerOS}" == "AIX" ]]; then

                       nexec -i ${host} lslpp -a -h >> ${folderPath}/${folderName}/runningProcesses.txt

             

              elif [[ "${ServerOS}" == "Linux" ]]; then

                   nexec -i ${host} rpm -qai >> ${folderPath}/${folderName}/installedRPMs.txt

       

                elif [[ "${ServerOS}" == "SunOS" ]]; then

                      nexec -i ${host} showrev –p >> ${folderPath}/${folderName}/runningProcesses.txt

             

          else

           echo "OS of not a valid type"    

      fi

      done <<< "${hostList}"

      ------------------------------------------------------------------------------------------------------------------------------------------

       

      However, no matter what the OS type is, it always goes to else and throws OS of not a valid type.

       

       

       

      May I know where I am getting wrong with the logic?

       

      Thanks,

      Parag