I'm afraid you can't make functions (like a normal programming does) in
cfengine.
To get closed to your expectation, you might need to create global variables
(bundle common) of the outputs of your commands/scripts then you could call it
up in every bundle. For instance;
body common control
{
bundlesequence => { "def","foo","bar" };
}
bundle common def
{
vars:
"global_result" string => execresult("/bin/ls /","noshell");
"global_split" slist => splitstring("$(global_result)"," ","100");
}
bundle agent foo
{
reports:
Yr2010::
"Found: $(def.global_result)";
}
bundle agent bar
{
vars:
"local_split" slist => { @(def.global_split) };
reports:
Yr2010::
"Found: $(local_split)";
}
Note that, you can only iterate common slist variable over local variables so
you need to pass a global slist variable to a local one in your bundle.
Cheers,
--Nakarin
On Apr 27, 2010, at 4:24 PM, Jakub Viták wrote:
> Hi again.
>
> If anyone have a little free time, I will be very grateful if give few
> tips about functions.
>
> Thank you, Jakub V.
>
> -------- Original Message --------
> Subject: Re: simple return array from other "code"
> Date: Mon, 26 Apr 2010 08:03:55 +0200
> From: Jakub Viták <[email protected]>
> To: Nakarin Phooripoom <[email protected]>
>
>
> Hello Nakarin.
>
> Thank you for quick response - it works :)
>
> On more question.
>
> Could I do same with agents? Or is it better to define var and let other
> part
> to work with it by global access.
>
> I am still little touched with normal programming :D
>
> Please see my example script - http://pastebin.intuxication.org/202
> (your - working way)
> and way I would like to have something like this -
> http://pastebin.intuxication.org/203
>
> Current error I have, with second example above
>
> [j...@dexter .cfagent]$ cf-agent -I -f ./fun2.cf
> cf3:./fun2.cf:18,27: Unknown built-in function gen(), near token ')'
> No such FnCall "gen()" in promise @ ./fun2.cf near line 18
>
>
> If I could summary my problem - I don't know howto make functions and
> call them
> on demand.
>
>
> Best regards, Jakub V.
>
>
> On 04/25/2010 11:58 PM, Nakarin Phooripoom wrote:
>> You could get a string from a shell command by execresult() then split the
>> string up to an slist by splitstring()
>>
>> ##########
>> vars:
>> "result" string => execresult("/bin/ls /","noshell");
>> "split" slist => splitstring("$(result)"," ","100");
>>
>> reports:
>> Yr2010::
>> "Found: $(split)";
>> ##########
>>
>> Cheers,
>> --Nakarin
>
>
> _______________________________________________
> Help-cfengine mailing list
> [email protected]
> https://cfengine.org/mailman/listinfo/help-cfengine
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine