Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-3558

Ability to report some number of lines from the END of a file

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Done
    • Priority: (None)
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.18.0
    • Component/s: None
    • Labels:
    • Story Points:
      0

      Description

      Currently, (as of 3.17.0) printfile bodies can be used to report the contents of a file from the top of the file, but there is not yet a way of printing the last several lines of a file. For example:

        bundle agent example_printfile(file)
        {
          reports:
            "The first two lines of '$(file)':"
              printfile => head_n( $(file), 2 );
      
            "The full content of '$(file)'"
              printfile => cat( $(file) );
        }
        bundle agent __main__
        {
          methods:
              "Print Self"
                usebundle => example_printfile($(this.promise_filename)); 
        }
      

      Outputs:

      R: The first two lines of '/home/nickanderson/org/cfengine3-gPoHAy':
      R: body file control{ inputs => { '$(sys.libdir)/stdlib.cf' };}
      R: bundle agent example_printfile(file)
      R: The full content of '/home/nickanderson/org/cfengine3-gPoHAy'
      R: body file control{ inputs => { '$(sys.libdir)/stdlib.cf' };}
      R: bundle agent example_printfile(file)
      R: {
      R:   reports:
      R:     "The first two lines of '$(file)':"
      R:       printfile => head_n( $(file), 2 );
      R: 
      R:     "The full content of '$(file)'"
      R:       printfile => cat( $(file) );
      R: }
      R: bundle agent __main__
      R: {
      R:   methods:
      R:       "Print Self"
      R:         usebundle => example_printfile($(this.promise_filename)); 
      R: }
      

      It would be nice if I could specify number_of_lines as a negative number, to print the end of the file, or perhaps a new body attribute to select a number of lines from the start or the end of the file.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                larsewi Lars Erik Wik
                Reporter:
                a10042 Nick Anderson
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel