1 2 Previous Next 15 Replies Latest reply on Sep 16, 2014 4:03 PM by Jegavelan Sargunan

    NSH Type 2-nexec

    Jegavelan Sargunan

      How do i run the nexec in NSH type 2 script ?

        • 1. Re: NSH Type 2-nexec
          Bill Robinson

          You should look at the man page – ‘man nexec’ from w/in nsh.

          • 2. Re: NSH Type 2-nexec
            Jegavelan Sargunan

            Whats wrong on this script  ?

             

            runBlcliQuery()

            {

                local server=${1}

                propertyName=${2}

                result=`blcli Server printPropertyValue ${server} ${propertyName}`

                echo "${result}"

            }

             

            for SERVER in ${@};

                do

                cd //@;disconnect

             

            OSTYPE=(`runBlcliQuery ${SERVER} "OS"`)

            EXIT="Y"

                [[ $OSTYPE == *Windows* ]] && EXIT="N"

                [[ $EXIT == "Y" ]] && echo "$SERVER -  Is Not Windows, Skipping" && continue

             

            OSVERSION=(`runBlcliQuery ${SERVER} "OS_VERSION"`)

            if [ "$OS_VERSION" = "2008" ]

            then

            echo "(${server})for entry in $(nexec -e qwinsta | awk ' /Listen/ {print $2}'); do nexec -e cmd /c "echo Y | rwinsta $entry";done\n"

            echo "(${server})for entry in $(nexec -e qwinsta | awk ' /Disc/ {print $2}'); do nexec -e cmd /c "echo Y | rwinsta $entry";done\n"   

            echo "(${server})for entry in $(nexec -e qwinsta | awk ' /Active/ {print $2}'); do nexec -e cmd /c "echo Y | rwinsta $entry";done\n"   

            else

            echo "(${server})nexec -e rwinsta 0\n"

            echo "(${server})nexec -e rwinsta 1\n"

            fi

            done

            exit 0

            • 3. Re: NSH Type 2-nexec
              Bill Robinson

              it depends, what's not working ?

              • 4. Re: NSH Type 2-nexec
                Jegavelan Sargunan

                I tested in a 2003 box, it just echoed the command and went on to exit but it does not ran the command which i wanted to run rwinsta 0 and rwinsta 1

                • 5. Re: NSH Type 2-nexec
                  Bill Robinson

                  so there's a few things i would do differently.

                  1 - don't use the blcli, you don't need it and it will slow down the script

                  2 - you are running a cd //@ then a disconnect so your '-e' won't work because you aren't cd'd into a server

                  3 - your for loop is going to get echoed, not run because it's not actually being run, just echoed...

                  4 - nexec isn't running because it's being echoed

                   

                  these all seem to be basic shell scripting issues.  i have no idea what the output of the qwinsta command looks like so i'm assuming your regex is ok there.

                   

                   

                  for SERVER in ${@};

                      do

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

                       EXIT="Y"

                       if [[ "${OSTYPE}" = "WindowsNT" ]]

                          then

                         OSVERSION="$(uname -D //${SERVER} -r)"

                         if [[ "${OSVERSION}" = "5.2" ]]

                            then

                           for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Listen/ {print $2}'

                            do

                                 echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                             done

                       elif [[ "${OSVERSION}" = "6.0" ]]

                            then

                           for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Listen/ {print $2}'

                            do

                                 echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                             done

                   

                           for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' Disc/ {print $2}'

                            do

                                 echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                             done

                   

                           for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Active/ {print $2}'

                            do

                                 echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                             done

                    else

                         echo "(${server}) $(nexec -e rwinsta 0)"

                         echo "(${server}) $(nexec -e rwinsta 1)"

                       else

                            echo "${SERVER} -  Is Not Windows, Skipping"

                            continue

                       fi

                  cd //@;disconnect ${SERVER}

                  done

                  • 6. Re: NSH Type 2-nexec
                    Jegavelan Sargunan

                    Thanks Bill for correcting me but I still get the error as nsh:73: parse error near `$(nexec ${SERVER} cm...'

                    I did use this documents for echoing the nexec https://communities.bmc.com/docs/DOC-30865


                    The script basically will disconnect all the session of the servers before reboot, because we have server where it will never reboot on whatever command issued from blade logic , need to manually logoff the users so it will help the server to get rebooted. Most of my users get locked at admin console, where in 2003 we can use rwinsta 0 but it will not work in 2008 as the ID assignment is different, so i cannot issue the rwinsta 0 to both 2003 and 2008 servers at the same time. So I am trying to achieve both in a single script so that all the users are logged off from the server so that i can make sure the server is getting rebooted properly

                     

                    I did modify the script to my own need even then i get the same error because of the exact syntax missing

                     

                     

                    for SERVER in ${@};

                     

                        do

                     

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

                     

                         EXIT="Y"

                     

                         if [[ "${OSTYPE}" = "WindowsNT" ]]

                     

                            then

                     

                           OSVERSION="$(uname -D //${SERVER} -r)"

                     

                           if [[ "${OSVERSION}" = "2008" ]]

                     

                              then

                     

                             for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Listen/ {print $2}'

                     

                              do

                     

                                   echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                     

                               done

                     

                     

                     

                             for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' Disc/ {print $2}'

                     

                              do

                     

                                   echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                     

                               done

                     

                     

                     

                             for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Active/ {print $2}'

                     

                              do

                     

                                   echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                     

                               done

                     

                         elif [[ "${OSVERSION}" = "2003" ]]

                     

                           echo "(${server}) $(nexec -e rwinsta 0)"

                     

                           echo "(${server}) $(nexec -e rwinsta 1)"

                     

                          else

                     

                              echo "${SERVER} -  Is Not Windows, Skipping"

                     

                              continue

                     

                         fi

                     

                    cd //@;disconnect ${SERVER}

                     

                    done

                    • 7. Re: NSH Type 2-nexec
                      Bill Robinson

                      missing a closing paren:

                      for SERVER in ${@};

                          do

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

                           EXIT="Y"

                           if [[ "${OSTYPE}" = "WindowsNT" ]]

                              then

                             OSVERSION="$(uname -D //${SERVER} -r)"

                             if [[ "${OSVERSION}" = "5.2" ]]

                                then

                               for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Listen/ {print $2}')

                                do

                                     echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                                 done

                           elif [[ "${OSVERSION}" = "6.0" ]]

                                then

                               for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Listen/ {print $2}')

                                do

                                     echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                                 done

                       

                               for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' Disc/ {print $2}')

                                do

                                     echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                                 done

                       

                               for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Active/ {print $2}')

                                do

                                     echo "(${server}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                                 done

                        else

                             echo "(${server}) $(nexec -e rwinsta 0)"

                             echo "(${server}) $(nexec -e rwinsta 1)"

                           else

                                echo "${SERVER} -  Is Not Windows, Skipping"

                                continue

                           fi

                      cd //@;disconnect ${SERVER}

                      done

                      t ${SERVER}

                      • 8. Re: NSH Type 2-nexec
                        Jegavelan Sargunan

                        Now again the same old error, where it says as no host to execute the command. The issue with this two lines of code

                         

                        echo "(${server}) $(nexec -e rwinsta 0)"

                         

                          echo "(${server}) $(nexec -e rwinsta 1)"

                         

                        • 9. Re: NSH Type 2-nexec
                          Bill Robinson

                          oh - case matters - $SERVER and $server are not the same thing.  pick a consistent case

                          • 10. Re: NSH Type 2-nexec
                            Jegavelan Sargunan

                            Not really with all upper case $SERVER  through out the script, but i do see different output now , but still no host to run

                             

                             

                             

                            for SERVER in ${@};

                             

                                do

                             

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

                             

                                 EXIT="Y"

                             

                                 if [[ "${OSTYPE}" = "WindowsNT" ]]

                             

                                    then

                             

                                   OSVERSION="$(uname -D //${SERVER} -r)"

                             

                                   if [[ "${OSVERSION}" = "2008" ]]

                             

                                       then

                             

                                     for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Listen/ {print $2}')

                             

                                      do

                             

                                           echo "(${SERVER}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                             

                                       done

                             

                             

                             

                                     for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' Disc/ {print $2}')

                             

                                      do

                             

                                           echo "(${SERVER}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                             

                                       done

                             

                             

                             

                                     for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Active/ {print $2}')

                             

                                      do

                             

                                           echo "(${SERVER}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                             

                                       done

                             

                                 elif [[ "${OSVERSION}" = "2003" ]]

                             

                                    

                                   echo "(${SERVER}) $(nexec -e rwinsta 0)"

                             

                                   echo "(${SERVER}) $(nexec -e rwinsta 1)"

                             

                                 else

                             

                                      echo "${SERVER} -  Is Not Windows, Skipping"

                             

                                      continue

                             

                                 fi

                             

                            cd //@;disconnect ${SERVER}

                             

                            done

                            • 11. Re: NSH Type 2-nexec
                              Bill Robinson

                              what are the input parameters to the script object ?

                              • 12. Re: NSH Type 2-nexec
                                Bill Robinson

                                oh - change the -e ${SERVER}

                                • 13. Re: NSH Type 2-nexec
                                  Jegavelan Sargunan

                                  Same error

                                   

                                   

                                   

                                  for SERVER in ${@};

                                   

                                      do

                                   

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

                                   

                                       EXIT="Y"

                                   

                                       if [[ "${OSTYPE}" = "WindowsNT" ]]

                                   

                                          then

                                   

                                         OSVERSION="$(uname -D //${SERVER} -r)"

                                   

                                         if [[ "${OSVERSION}" = "2008" ]]

                                   

                                             then

                                   

                                           for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Listen/ {print $2}')

                                   

                                            do

                                   

                                                 echo "(${SERVER}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                                   

                                             done

                                   

                                   

                                   

                                           for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' Disc/ {print $2}')

                                   

                                            do

                                   

                                                 echo "(${SERVER}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                                   

                                             done

                                   

                                   

                                   

                                           for entry in $(nexec ${SERVER} cmd /c "qwinsta" | awk ' /Active/ {print $2}')

                                   

                                            do

                                   

                                                 echo "(${SERVER}) $(nexec ${SERVER} cmd /c "echo Y | rwinsta ${entry}")"

                                   

                                             done

                                   

                                       elif [[ "${OSVERSION}" = "2003" ]]

                                   

                                          

                                         echo "(${SERVER}) $(nexec -e ${SERVER} rwinsta 0)"

                                   

                                         echo "(${SERVER}) $(nexec -e ${SERVER} rwinsta 1)"

                                   

                                       else

                                   

                                            echo "${SERVER} -  Is Not Windows, Skipping"

                                   

                                            continue

                                   

                                       fi

                                   

                                  cd //@;disconnect ${SERVER}

                                   

                                  done

                                  • 14. Re: NSH Type 2-nexec
                                    Bill Robinson

                                           echo "(${SERVER}) $(nexec -e ${SERVER} rwinsta 0)"

                                     

                                           echo "(${SERVER}) $(nexec -e ${SERVER} rwinsta 1)"

                                     

                                    should be

                                     

                                           echo "(${SERVER}) $(nexec ${SERVER} rwinsta 0)"

                                     

                                           echo "(${SERVER}) $(nexec ${SERVER} rwinsta 1)"

                                    1 2 Previous Next