6 Replies Latest reply on Jan 15, 2017 5:37 PM by Bill Robinson

    Need help with nexec script

    Paul O'Malley

      Hi everyone:

       

      I have the following Type 2 NSH script that gets a list of targets passed in using the %h macro

       

       

      #!/bin/nsh

       

      #

       

      # Introscope Property Variables

       

      #

       

      #

       

      set -e

       

       

       

      MailList=paul.omalley@bankofamerica.com

       

      MailFile=/tmp/introscope_test.out

       

       

       

      serverList="${1}"

       

       

       

      for server in ${serverList}

       

      do

       

        echo $server >> $MailFile

       

        nexec $server "echo 'HOSTNAME: $(hostname)'" >> $MailFile

       

        nexec $server "echo 'UPDATE: $(uptime)'" >> $MailFile

       

        nexec $server "echo 'DATE: $(date)'" >> $MailFile

       

        nexec $server "echo 'INTROSCOPE ARSERVERD.CONF PROPERTY: $(cat /remedy/ars/ARSystem/bin/arserverd.conf | grep introscope)'" >> $MailFile

       

        nexec $server "echo 'INTROSCOPE ARSERVER PROPERTY: $(grep -A 5 'org.osgi.framework.bootdelegation' /remedy/ars/ARSystem/conf/config.properties)'" >> $MailFile

       

        nexec $server "echo 'INTROSCOPE SQL METRICS PROPERTY: $(cat /remedy/introscope_standalone_V10/introscope/core/config/bofa/REMEDYITSM.profile | grep turnoffmetrics)'" >> $MailFile

       

        echo "==============================================" >> $MailFile

       

      done

       

       

       

      mail -s "Introscope Test" $MailList < $MailFile

       

       

       

      exit 0

       

      The commands on the nexec lines seem to be running on the local application server instead of $server ... Did I mess up the quoting?

       

      How do I get the echo, cat, grep, etc in each nexec line to execute on the target?

       

      Thanks,

      Paul

        • 1. Re: Need help with nexec script
          Matt Moss

          You may need to use -ncq because of the quotes. Remove the singlequotes and move the echo to before the doublequotes.

           

               nexec -ncq $server echo "HOSTNAME: $(hostname)" >> $MailFile

           

          Or, you could just make a variable with the hostname command, then echo it into the MailFile

           

               GETHOST=`nexec $server hostname`

               echo "HOSTNAME: $GETHOST" >> $MailFile

           

          Using singlequotes will simply display everything inside the singlequotes and not the text and variable value.

           

          For instance:

           

                 nexec $server "echo 'UPDATE: $(uptime)'" >> $MailFile

           

          will output into MailFile something like.....

           

                 UPDATE: $(uptime)

           

           

          Hope this helps!

           

          Matt

          • 2. Re: Need help with nexec script
            Paul O'Malley

            Hi Matt:

             

            Here is my dilemma.. The hostname command seems to run on the application server the job is assigned to rather than the target host.

             

            ==> lrche0wgpap.ussdntb.amrs.bankofamerica.com <==

            lrche0wgpap.ussdntb.amrs.bankofamerica.com

            HOSTNAME: lpnobj55pappri.uspnoct.amrs.bankofamerica.com

             

            As you can see above, the server being passed in is lrche0wgpap.ussdntb.amrs.bankofamerica.com

             

            This line:

            runcmd -h $server -e "hostname" >> $MailFile

            produces the expected output:

            lrche0wgpap.ussdntb.amrs.bankofamerica.com

             

            but I can't prefix with the word HOSTNAME:

             

            This line:

            nexec -ncq $server echo "HOSTNAME: $(hostname)" >> $MailFile

            produces this output:

            HOSTNAME: lpnobj55pappri.uspnoct.amrs.bankofamerica.com

             

            lpnobj55pappri.uspnoct.amrs.bankofamerica.com is the Bladelogic application server the job ran on, not the target host.

             

            Any ideas?

            Thanks,

            Paul

            • 3. Re: Need help with nexec script
              Matt Moss

              Hi Paul,

               

              Give this a try in your for loop:

               

                   GETHOST=`nexec $server hostname`

                   echo "HOSTNAME: $GETHOST" >> $MailFile

              • 4. Re: Need help with nexec script
                Paul O'Malley

                Matt:

                 

                That worked perfectly!  Thanks very much!

                 

                Paul

                • 5. Re: Need help with nexec script
                  Ashish Vijay

                  Hello,

                   

                  Another way to achieve it with below one line commands

                   

                  nexec $server "echo HOSTNAME: |tr '\n' '\t' ; hostname" >> $MailFile

                  nexec $server "echo UPTIME: |tr '\n' '\t' ; uptime" >> $MailFile

                  • 6. Re: Need help with nexec script
                    Bill Robinson

                    you know you don't need to use 'cat | grep' right ?  'grep' works just fine...