Forum: Cfengine Help
Subject: Re: Edit selected files
Author: Beto
Link to topic: https://cfengine.com/forum/read.php?3,17747,17772#msg-17772

Hey folks,

Having no success whatsoever with the previous approaches in this thread I 
tried using a find command to select the "dot" files for editing.  Still no joy.

Just as in my previous approaches where it appeared that, no matter how I 
tried, I could not get a file_select to work with edit_line, now I can't get 
the splitstring function to return a value regardless of what I do.  For 
example: 

body common control
{
bundlesequence          => {
                        "check_user_files"
                        };

inputs                  => {
                        "cfengine_stdlib.cf",
                        "library.cf"
                        };
}

bundle agent check_user_files
{
vars:
        "HomeDirn"      int     => readstringarray(
                                "HomeDir",
                                "/etc/passwd",
                                
".*:[*x]:([1-9]|\d{2}|1\d{1,2}|-2|204|205|430|65534|4294967294|1000):.*",
                                ":",
                                "300",
                                "12000"
                                );

        "HomeUsr"       slist   => getindices("HomeDir");

        "HomeIni[$(HomeUsr)]"   string  => execresult("/usr/bin/find 
$(HomeDir[$(HomeUsr)][5]) \
                -path \"$(HomeDir[$(HomeUsr)][5])/.*\" -prune -type 
f","noshell");

        "IniFiles[$(HomeUsr)]"  slist   => 
splitstring("$(HomeIni[$(HomeUsr)])","[ \n]","999");

files:
        "$(IniFiles[$(HomeUsr)])"
                edit_line       => ini_file_update,
                edit_defaults   => no_edit_backup;

reports:
   hpux|linux::
        "$(IniFiles$(HomeUsr))";

        "$(HomeIni[$(HomeUsr)])";
}

bundle edit_line ini_file_update
{
replace_patterns:

        "old_value"
                replace_with    => value("new_value");
}

body  edit_defaults no_edit_backup
{
edit_backup     => "false";
}

This produces the following:

cf3     .........................................................
cf3     Promise handle: 
cf3     Promise made by: $(IniFiles)
cf3     .........................................................
cf3 
cf3  -> Using regex pathtype for $(IniFiles) (see pathtype)
cf3  -> Using best-effort expanded (but non-existent) file base path $(IniFiles)
cf3  ** Information: the proposed file "$(IniFiles)" could not be loaded
cf3  !!! System error for stat: "No such file or directory"
cf3 File $(IniFiles) was marked for editing but could not be opened

cf3     .........................................................
cf3     Promise handle: 
cf3     Promise made by: $(IniFilesusera)
cf3     .........................................................
cf3 
cf3 Reporting about this...
cf3 R: $(IniFilesusera)

cf3     .........................................................
cf3     Promise handle: 
cf3     Promise made by: /home/dit/usera/.cshrc
/home/dit/usera/.exrc
/home/dit/usera/.login
/home/dit/usera/.profile
/home/dit/usera/.hist3865
cf3 
cf3 Reporting about this...
cf3 R: /home/dit/usera/.cshrc
/home/dit/usera/.exrc
/home/dit/usera/.login
/home/dit/usera/.profile
/home/dit/usera/.hist3865


>From the output above I know that the find command produces the desired 
>result: a string containing the selected "dot" files.

But the splitstring function evidently isn't returning anything (i.e., the 
IniFiles array is null) which causes an error for the edit_line promise and the 
first report promise.

Am I brain dead?

As always, all comments appreciated.

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to