www.delorie.com/gnu/docs/cfengine/cfengine-Tutorial_37.html   search  
Buy GNU books!

GNU cfengine

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9 Recursive file sweeps/directory traversals

File sweeps are searches through a directory tree in which many files are examined and considered for processing in some way. There are many instances where one uses cfagent to perform a file sweep.

The problem with file sweeps is that they can be too sweeping! Often you are not interested in examining every single file in a file tree. You might wish to perform a search

The tidy action is slightly different in this respect, since it already always expects to match a specific pattern. One is generally not interested in a search which deletes everything except for a named pattern: this would be too dangerous. For this reason, the syntax of tidy does not allow ignore,include and exclude. It is documented in the section on tidying, (see Reference manual).

Items declared under the global ignore section affect files, copy, links and tidy. For file sweeps within files, copy and links, you may provide private ignore lists using ignore=. The difference between exclude and ignore is that ignore can deal with absolute directories. It prunes directories, while exclude only looks at the files within directories.

For file sweeps within files and copy you can specify specific search parameters using the keywords include= and exclude= and as of version 1.6.x filter=. For example,

   /usr/local/bin m=0755 exclude=*.ps action=fixall

In this example cfagent searches the entire file tree (omitting any directories listed in the ignore-list and omitting any files ending in the extension `.ps'), (see Reference manual).

Specifying the include= keyword is slightly different since it automatically restricts the search to only named patterns (using * and ? wildcards), whenever you have one or more instances of it. If you include patterns in this way, cfagent ignores any files which do not match the given patterns. It also ignores any patterns which you have specified in the global ignore-list as well as patterns excluded with exclude=pattern. In other words, exclusions always override inclusions.

If you exclude a pattern or a directory and wish to treat it in some special way, you need to code an explicit check for that pattern as a separate entity. For example, to handle the exluded `.ps' files above, you would need to code something like this:

   /usr/local/bin m=0644 include=*.ps action=fixall

Note: don't be tempted to enclose your wildcards in quotes. The quotes will be treated literally and the pattern might not match the way you would expect.

For editfiles the syntax is somewhat different. Here one needs to add lines to the edit stanza:


 { /tmp/testdir

 Include .*
 Exclude bla.*
 Ignore "."
 Ignore ".."
 Recurse 6

 ReplaceAll "search" With "replace"

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003