It turns out a simple "grep -v grep" at the end of the shell command did
the trick:
"myarray[$(mykeys)]" string => execresult("/usr/bin/ps -f | grep
$(mylist[$(mykeys)]) | grep -v grep","useshell");
On May 14, 2010 8:05pm, Michael Potter <mega...@gmail.com> wrote:
On Fri, May 14, 2010 at 4:58 PM, Сева Глущенко seva.glusche...@gmail.com>
wrote:
The following promise
"myarray[$(mykeys)]" string => execresult("/usr/bin/ps -f | grep
$(mylist[$(mykeys)])","useshell");
will expand not the way you expecting it. It doesn't mean
"myarray[a]" string => execresult("/usr/bin/ps -f | grep
$(mylist[a])","useshell");
"myarray[b]" string => execresult("/usr/bin/ps -f | grep
$(mylist[b])","useshell");
"myarray[c]" string => execresult("/usr/bin/ps -f | grep
$(mylist[c])","useshell");
Instead, it means
"myarray[a]" string => execresult("/usr/bin/ps -f | grep
$(mylist[a])","useshell");
"myarray[a]" string => execresult("/usr/bin/ps -f | grep
$(mylist[b])","useshell");
"myarray[a]" string => execresult("/usr/bin/ps -f | grep
$(mylist[c])","useshell");
and so forth.
I am not sure this is correct. For example, this bundle...
bundle agent atest {
vars:
"mylist[a]" string => "1";
"mylist[b]" string => "2";
"mylist[c]" string => "3";
"mykeys" slist => getindices("mylist");
"myarray[$(mykeys)]" string => execresult("/bin/echo
say_$(mylist[$(mykeys)]) | grep $(mylist[$(mykeys)])","useshell");
reports:
Yr2010::
">>$(myarray[$(mykeys)])";
}
...will print out reports as I expect, and without the error messages
before. So clearly, I can iterate over a list as part of an lvar in an
expression.
$ cf-agent -KI -f ./testbundle.cf
R: >>say_1
R: >>say_2
R: >>say_3
There seems to be something particular output the output of 'ps' that is
somehow causing it to trip up...that being said I can always run without
-I (which is what I do anyway), and the errors are not displayed but the
result is OK.
If you really need to operate processes, I'd rather suggest you using
process_select. If your task lays somewhere else, describe it more
clearly.
2010/5/14 mega...@gmail.com>:
> For me, the following bundle:
>
> bundle agent atest {
>
> vars:
>
> "mylist[a]" string => "1";
> "mylist[b]" string => "2";
> "mylist[c]" string => "3";
>
> "mykeys" slist => getindices("mylist");
>
> "myarray[$(mykeys)]" string => execresult("/usr/bin/ps -f | grep
> $(mylist[$(mykeys)])","useshell");
> }
>
> Produces the following errors:
>
> $ cf-agent -KI -f ./testbundle.cf
> Truncating long file /opt/atws/files/BUILT4 in readfile to max limit 4
> !! Duplicate selection of value for variable "myarray[a]" in scope atest
> Rule from ./roles/vnc.cf at/before line 27
> !! Duplicate selection of value for variable "myarray[b]" in scope atest
> Rule from ./roles/vnc.cf at/before line 27
> !! Duplicate selection of value for variable "myarray[c]" in scope atest
> Rule from ./roles/vnc.cf at/before line 27
>
> Can anyone else replicate this? And/or tell me what the issue is?
>
> I am using stock 3.04 on Solaris10/SPARC.
>
> Cheers
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine
>
>
--
SY, Seva Gluschenko.
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine