9 Replies Latest reply on Dec 1, 2011 11:57 AM by Bill Robinson

    nsh script for finding file diff on the target systems

      I am working on a nsh script for finding file diff between target systems, as follows -

       

      ===================================================================
      # nsh script to find the file diff between two hosts. That is,
      # nsh diff between //hostA/tmp/foo.txt //hostB/tmp/foo.txt
      blcli_setoption serviceProfileName defaultProfile
      blcli_setoption roleName P_O_E
      blcli_connect

      fileName="${1}"
      host1="${2}"
      host2="${3}"

      blcli_execute ${fileName} getDBKeyByGroupAndName "${host1}" "${host2}"
      blcli_storeenv

      # append the pid of the shell to the diff output
      nsh diff //${host1}/tmp/${fileName} //${host2}/tmp/${fileName}|tee -a /tmp/diff_$$.txt

       

      The host names and file name will be parameterized. need help with completing the blcli part.

      -----

      a few follow up questions

      1). what should be the file location for nsh scripts ? can it reside in the local file system ? or should it

      reside in the app server ?. This is while creating nsh script object in the gui. I believe it is step 1.

      2) How can I extend the above steps for the script, to directory level comparison ?

      3) host 1 will be constant. But host 2 could be 15 other hosts. how can the comparison still be done ?

      4) if 2) and 3) are possible, creating the output and mailing the same should be granular. Like, file 7

      is different on host 9 and host 10, and the diff is as follows : List the diff.

      -----

      Appreciate any help with nsh script creation for this task.

        • 1. Re: nsh script for finding file diff on the target systems

          You don’t need any blcli here. Make it a type 1 script targeted against the appserver and using the three parameters as you said below. Add a new NSH script to the depot and add the three parameters, ordered in the correct sequence, in the depot. The diff will be captured in the job log.

           

          #!/bin/nsh

          #Declare vars

          #FULLPATH should be in NSH context ‘/c/Windows/foo/bar’

          FULLPATH=$

          HOSTA=$

          HOSTB=$

          #Do the diff

          diff //$$ //$$

          #end script

           

          But all of that being said, it is far easier and a lot more functional to just do this type of thing with an audit job. But, nonetheless, there you go. This should work for a file or a directory (‘man diff’ in NSH for more options with diff)

          • 2. Re: nsh script for finding file diff on the target systems

            I have the nsh script as follows -

             

            #!/bin/nsh

             

            HOST1="${1}"
            HOST2="${2}"
            FULLPATH="${3}"

            diff //${HOST1}/${FULLPATH} //${HOST2}/${FULLPATH}

             

            All the parameters are parameterized appropriately. not using any blcli commands as you mentioned.

            a few questions -
            1) Don't see any Transactions Log (Job Log) getting created on HOST1 or HOST2. why ?
            2) I look at the exit status of the diff command in nsh. It is '1' when there is a diff, and '0' when the files are identical. I am interested in knowing whenever there is a diff. This means I will always get "Job Failed" notification. Not sure how to work around this and get what I want.
            3) I also see the following in the appserver log -

            [01 Nov 2011 12:33:48,899] [WorkItem-Thread-21] [INFO]

            [xyz@abc:P_O_E:] [NSHScript] Executing work item NSH Script Job:cfg_diff; Server:123.com;  on application server: prdbl1

            DEBUG    rscd -  prdbl1 7236 -1/-1 (???): ???: NOT AGENT - FIPS Disabled

            Roll File Open Failed[01 Nov 2011 12:33:48,899] [WorkItem-Thread-21] [INFO]

             

            appreciate any suggestions.

            • 3. Re: nsh script for finding file diff on the target systems
              Bill Robinson

              1 - transaction logs are only for deploy jobs.  this is not a deloy job.

              2 - you can capture the exit code and exit w/ whatever you want - eg

               

              diff blah blah

              if [ $? -eq 1 ]

                   then

                   echo "THERE IS A DIFFERENCE"

                   exit 0

              else

                   echo "NO DIFF"

                   exit 0

              fi

               

              what is 'NOT AGENT' ?

               

              why don't you use an audit job?

              • 4. Re: nsh script for finding file diff on the target systems

                at this point component template, components from the top level menu, are disabled. Working with our admin and that would take sometime. Hence, looking at the option of nsh script.

                Not sure about that 'NOT AGENT' thing. It appeared in the appserver log. Assumed it would give some clues.

                • 5. Re: nsh script for finding file diff on the target systems
                  Bill Robinson

                  You can create an audit job w/o a template, assuming the paths are the same.

                   

                  Other than that fips message, the job is running ?

                  • 6. Re: nsh script for finding file diff on the target systems

                    The nsh script job was not running to the completion. So, created an audit job, per your suggestion -

                    Master Server=host1, server objects = /tmp/zz.txt (file type)

                    chose the snapshot/audit options for size and contents

                    run against target=host2

                    when I look at the run details, though it shows 'Status: Running' the message

                    column is "Access Denied Server.Audit on host1.zz.com"

                    Looks like, privileges are missing ?

                    • 7. Re: nsh script for finding file diff on the target systems
                      Bill Robinson

                      Yep – you need a mapping against the target servers for your role/user, also you need ‘Server.Audit’ on the targets.

                      • 8. Re: nsh script for finding file diff on the target systems

                        couple of questions in continuation to nsh part of the original query -

                        1/  host1 is a master host (constant) currently while host2 parameter is  host (vari able) against which diff is run. How can I run the nsh job against multiple (variable) hosts ? dont want to change the host2 parameter everytime.

                        2/ How can I get a per host basis report ? Like -  list of added files, deleted files, unchanged files and for all the modified files, report the diff per file basis

                         

                        not intersted in  the usual job notification - where it says "job finished" "job failed" with failed host name.

                         

                        I will come to 'Server.Audit' part later. Right now, looking at nsh script possibility.

                        • 9. Re: nsh script for finding file diff on the target systems
                          Bill Robinson

                          you should use an audit job.  this is exactly what it is designed for.  by trying to do this in nsh you are re-inventing the wheel...