Forum: Cfengine Help
Subject: dynamic variable declaration
Author: bglomm
Link to topic: https://cfengine.com/forum/read.php?3,18441,18441#msg-18441

hi all,

Could anybody give me a hint on how to construct variable names during runtime 
(amount and names shall come from a "ls" command on a specific directory) and 
fill each of this variables with a value extracted from the corresponding file?


What I tried: 

In /localhost/somelocation/
there are a bunch of files, let's say: test1, test2, othertest3 (arbitrary 
unknown names).
each of this files contains a tagged line that I can get with egrep... and 
extract with a simple cut...
Now I like to build an array of the form:
myarray string => "extracted-value-from-file-test1"
myarray string => "extracted-value-from-file-test2"
myarray string => "extracted-value-from-file-othertest3"

in the "var:" section I can do a

"allfiles" string => execresult("/bin/ls -x /localhost/somelocation/", 
"noshell");
"allfiles_array" slist => splitstring("$allfiles)", "\W", "20");
... so far all fine and works, but now I would need something like:

"string[$(myarray)] string => execresult("/bin/egrep \"mypatter\" 
/localhost/somelocation/$(myarray) | cut ...", "noshell")

but that doesn't work (Variable identifier contains illegal character, i.e. the 
$ ...)

TIA

Bernhard

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

Reply via email to