6 Replies Latest reply on Jan 21, 2016 6:28 AM by Bill Robinson

    BBSA Job execution and capturing output in a file

    Navya MS

      Hi Team,


      We have a requirement to execute a command and capture the output in a single file. Is there a way to achieve this requirement where, we execute a job against a set of servers and the job runs a command against those servers and allow us to export the output.

      Can this be achieved without using the command prompt and Nexec commands?

       

      Environmental Details:

      1. Operating System: Microsoft Windows server 2008 R2
      2. Operating System Patches: Service Pack 1
      3. System Type: 64 – bit OS
      4. BMC Bladelogic: Version 8.2.04.437

       

      Please help us in resolving the issue.

       

      Regards,

      Navya M S

        • 1. Re: BBSA Job execution and capturing output in a file
          Santhosh Kurimilla

          If it is NSH script job, simply redirect your output to a remote file like:

           

          echo "Command result" >> //remote_srvr/path/of/the/file.log

           

          The preferred remote_srvr is Your file server. Otherwise, you can use any Server share where agent is accessible.

          • 2. Re: BBSA Job execution and capturing output in a file
            Jim Wilson

            Discussion successfully moved from  BladeLogic to Server Automation

            • 3. Re: BBSA Job execution and capturing output in a file
              Bill Robinson

              there is no way to run a command against a remote server and not use nexec.  even the 'type 3' script will use nexec to run the script.

               

              can you provide an example of what you are trying to do (eg, the command) and where you want the output to go (on the server itself, on a central location, etc) ?

              • 4. Re: BBSA Job execution and capturing output in a file
                Navya MS

                Hello Bill,

                 

                Please find an example requirement below:

                I am running a set of commands on 200 machines. I would like to get an output file (probably an excel) which has the output of each command run on the remote machines.

                Say,

                I run the below commands on 200 remote machines,

                 

                cat /var/adm/auth.log | grep -iv vty | grep -ic "Accepted password for root"

                lsb_release -r | awk -F: '{print $2}'

                 

                I can see from the output log file that these commands got executed successfully. But I am unable to get hold of the output of these commands for all 200 machines which is a need for my audit project.

                 

                Regards,

                Navya M S

                • 5. Re: BBSA Job execution and capturing output in a file
                  Santhosh Kurimilla

                  You may try it through NSH Type2 Script, something as below:

                   

                  ================================================

                  #!/bin/nsh

                   

                  APPSERVER=`hostname`

                   

                  SERVERS_LIST="${1}"

                   

                  echo "SERVER Name,Acceptance Count,Release" //$APPSERVER/tmp/output.csv

                  for SERVER in $SERVERS_LIST

                  do

                    COUNT=$(cat //$SERVER/var/adm/auth.log | grep -iv vty | grep -ic "Accepted password for root")

                    RELEASE=$(nexec $SERVER "lsb_release -r | awk -F: '{print $2}'")

                    echo "$SERVER,$COUNT,"${RELEASE}"" >> //$APPSERVER/tmp/output.csv

                  done

                   

                  cd /tmp

                   

                  blcli Email sendMailWithAttachment Your_BL_Email@bladelogic.com Your_mail_ID@Your_official.com "root Password Acceptance Count" "Please go through the attched file" . "output.csv"

                   

                  echo "output.csv file has been sent from the AppServer $APPSERVER"

                  ================================================

                  • 6. Re: BBSA Job execution and capturing output in a file
                    Bill Robinson

                    yep. also there's no need to cat the file and then grep the output.  just grep it:

                     

                    grep -iv vty "//${SERVER}/var/adm/auth.log" | grep -ic  "Accepted password for root""

                     

                    and instead of

                      RELEASE=$(nexec $SERVER "lsb_release -r | awk -F: '{print $2}'")

                    you can do

                    nexec ${SERVER} "lsb_release -r | awk -F: '{print $2}' > file

                     

                    or just

                     

                    echo "${SERVER},$(grep -iv vty "//${SERVER}/var/adm/auth.log" | grep -ic  "Accepted password for root"),$(nexec ${SERVER} "lsb_release -r | awk -F: '{print $2}')" >> //@/tmp/output.csv

                     

                    in the loop