No idea how long I would have poked around in the docs before finding this, thanks.
On Apr 26, 2011, at 4:38 AM, Francoeur, Louis wrote: > If you don't want the messages about redefinition of constant, > You have to add: > policy => "free" > to your variable. > > Example: > "jobs_in_queue" string => execresult("/usr/bin/lpstat -o -i | > /usr/bin/grep \"^$(queue)-\" | /usr/bin/wc -l", "useshell"), > policy => "free"; > > Louis Francoeur > Unix administrator/Adminstrateur Unix > > -----Original Message----- > From: help-cfengine-boun...@cfengine.org > [mailto:help-cfengine-boun...@cfengine.org] On Behalf Of Jesse Becker > Sent: Monday, April 25, 2011 10:16 PM > To: Michael Stevens > Cc: help-cfengine > Subject: Re: Avoiding "Duplicate selection of value" > > On Mon, Apr 25, 2011 at 08:21:21PM -0400, Michael Stevens wrote: >> Is there a preferred method for getting variables using randomint() to stop >> getting defined once they're set, eg, avoid this; >> >> !! Redefinition of a constant scalar "rnd" (was 2786 now 195) >> !! Redefinition of a constant scalar "rnd" (was 195 now 2749) >> !! Redefinition of a constant scalar "rnd" (was 2749 now 1852) >> >> >> I'm trying to set a randomized 0/60 minute delay on a command that runs >> once a day so that all the machines don't fire right at the same time and >> overload a file server the command tells them to grab a bunch of files from. >> If there's a better way to do this than embedding an "at" or "sleep" in my >> command, let me know ... > > This isn't a direct answer to your question, but I had to do something > similar. I wanted the clients to consistantly choose a host from a > list (it happens to be a list of two hosts, but the idea should scale). > > I used something like this (untested, use at own risk, formatting > adjusted for clarity in email): > > bundle agent foo { > > vars: > hostname_hash string => hash(getenv("HOSTNAME","40"),'md5'); > servername string => execresult( > "/bin/echo > ${hostname_hash} | > /bin/cut -c -16 | > perl -e perl > statement could'll=qw(hostA hostB);' > -e > '$L=scalar @l;' > -e 'print $l[hex(<>)%$L];' > "useshell"); > } > > I actually think this a bit better than a purely random number that > changes each time. This should give you a "random", but consistant > value for each hostname. > > In your case, you just want a number 0-60, so the execresult command > could be replaced with something like: > > /bin/echo ${hostname_hash} | > /bin/cut -c -16 | > perl -e 'print <>%61;'" > > > Note that I've clipped only 16 characters, instead of the full 32 that > come from md5sum, in order to avoid integer overflows in Perl. > > > -- > Jesse Becker > NHGRI Linux support (Digicon Contractor) > _______________________________________________ > Help-cfengine mailing list > Help-cfengine@cfengine.org > https://cfengine.org/mailman/listinfo/help-cfengine _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine