Dear all,
I see that writing a custom-fact with single line of command is not
that tough, like this:
****************************
Facter.add("num_core") do
setcode do
%x{/bin/grep siblings /proc/cpuinfo | uniq | cut -d" " -f
2}.chomp
end
end
****************************
But that''s not enough for me. What I actually need to do is something
like this:
dd_code=`which dmidecode`
n1=`${dd_code} -t processor | grep -c "Socket Designation"`
n2=`${dd_code} -t processor | grep "Core Count" | uniq | cut -d"
" -
f3`
n=$(($n1*$n2))
How can I put this in the "fact"? Cheers!!
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
One option is to save dd_code lines as a separate script, have puppet ensure its presence on each machine with a file statement, and then call it by explicit path in the Facter.add block. -- Peter (from phone) On Jun 14, 2011, at 7:39 AM, Sans <r.santanu.das@gmail.com> wrote:> Dear all, > > I see that writing a custom-fact with single line of command is not > that tough, like this: > > **************************** > Facter.add("num_core") do > setcode do > %x{/bin/grep siblings /proc/cpuinfo | uniq | cut -d" " -f > 2}.chomp > end > end > **************************** > > But that''s not enough for me. What I actually need to do is something > like this: > > dd_code=`which dmidecode` > n1=`${dd_code} -t processor | grep -c "Socket Designation"` > n2=`${dd_code} -t processor | grep "Core Count" | uniq | cut -d" " - > f3` > n=$(($n1*$n2)) > > > How can I put this in the "fact"? Cheers!! > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Surely, I can do "/usr/sbin/dmidecode -t processor | grep -c "Socket Designation" etc. - that''s not a problem. My question is: How to do the rest in the "fact"? Anyone one care to make a sample script out of that, which will be lot easier for me to understand how this thing works. Cheers!! On Jun 14, 12:46 pm, Peter Bukowinski <pmb...@gmail.com> wrote:> One option is to save dd_code lines as a separate script, have puppet ensure its presence on each machine with a file statement, and then call it by explicit path in the Facter.add block. > > -- > Peter (from phone) > > On Jun 14, 2011, at 7:39 AM, Sans <r.santanu....@gmail.com> wrote: > > > > > > > > > Dear all, > > > I see that writing a custom-fact with single line of command is not > > that tough, like this: > > > **************************** > > Facter.add("num_core") do > > setcode do > > %x{/bin/grep siblings /proc/cpuinfo | uniq | cut -d" " -f > > 2}.chomp > > end > > end > > **************************** > > > But that''s not enough for me. What I actually need to do is something > > like this: > > > dd_code=`which dmidecode` > > n1=`${dd_code} -t processor | grep -c "Socket Designation"` > > n2=`${dd_code} -t processor | grep "Core Count" | uniq | cut -d" " - > > f3` > > n=$(($n1*$n2)) > > > How can I put this in the "fact"? Cheers!! > > > -- > > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > > For more options, visit this group athttp://groups.google.com/group/puppet-users?hl=en.-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Is this what your after? http://projects.puppetlabs.com/projects/1/wiki/Dmidecode_Patterns Cheers, Den On 14/06/2011, at 22:03, Sans <r.santanu.das@gmail.com> wrote:> Surely, I can do "/usr/sbin/dmidecode -t processor | grep -c "Socket > Designation" etc. - that''s not a problem. My question is: How to do > the rest in the "fact"? Anyone one care to make a sample script out of > that, which will be lot easier for me to understand how this thing > works. Cheers!! > > > On Jun 14, 12:46 pm, Peter Bukowinski <pmb...@gmail.com> wrote: >> One option is to save dd_code lines as a separate script, have puppet ensure its presence on each machine with a file statement, and then call it by explicit path in the Facter.add block. >> >> -- >> Peter (from phone) >> >> On Jun 14, 2011, at 7:39 AM, Sans <r.santanu....@gmail.com> wrote: >> >> >> >> >> >> >> >>> Dear all, >> >>> I see that writing a custom-fact with single line of command is not >>> that tough, like this: >> >>> **************************** >>> Facter.add("num_core") do >>> setcode do >>> %x{/bin/grep siblings /proc/cpuinfo | uniq | cut -d" " -f >>> 2}.chomp >>> end >>> end >>> **************************** >> >>> But that''s not enough for me. What I actually need to do is something >>> like this: >> >>> dd_code=`which dmidecode` >>> n1=`${dd_code} -t processor | grep -c "Socket Designation"` >>> n2=`${dd_code} -t processor | grep "Core Count" | uniq | cut -d" " - >>> f3` >>> n=$(($n1*$n2)) >> >>> How can I put this in the "fact"? Cheers!! >> >>> -- >>> You received this message because you are subscribed to the Google Groups "Puppet Users" group. >>> To post to this group, send email to puppet-users@googlegroups.com. >>> To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. >>> For more options, visit this group athttp://groups.google.com/group/puppet-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Not pretty - but hacking up your example to work in ruby should be
something like:
Facter.add("num_core") do
setcode do
dd_code=`which dmidecode`.chomp
n1=`#{dd_code} -t processor | grep -c "Socket
Designation"`.chomp.to_i
n2=`#{dd_code} -t processor | grep "Core Count" | uniq | awk
''{print $3}''`.chomp.to_i
n1*n2
end
end
The key things here are the chomps to remove newlines, the #{} format
for variable interpolation in strings and the to_i to get integers.
Also not the n1*n2 at the end - this will return the result (no need
for return unless you want it).
ken.
On Tue, Jun 14, 2011 at 1:03 PM, Sans <r.santanu.das@gmail.com>
wrote:> Surely, I can do "/usr/sbin/dmidecode -t processor | grep -c
"Socket
> Designation" etc. - that''s not a problem. My question is: How
to do
> the rest in the "fact"? Anyone one care to make a sample script
out of
> that, which will be lot easier for me to understand how this thing
> works. Cheers!!
>
>
> On Jun 14, 12:46 pm, Peter Bukowinski <pmb...@gmail.com> wrote:
>> One option is to save dd_code lines as a separate script, have puppet
ensure its presence on each machine with a file statement, and then call it by
explicit path in the Facter.add block.
>>
>> --
>> Peter (from phone)
>>
>> On Jun 14, 2011, at 7:39 AM, Sans <r.santanu....@gmail.com>
wrote:
>>
>>
>>
>>
>>
>>
>>
>> > Dear all,
>>
>> > I see that writing a custom-fact with single line of command is
not
>> > that tough, like this:
>>
>> > ****************************
>> > Facter.add("num_core") do
>> > setcode do
>> > %x{/bin/grep siblings /proc/cpuinfo | uniq | cut -d"
" -f
>> > 2}.chomp
>> > end
>> > end
>> > ****************************
>>
>> > But that''s not enough for me. What I actually need to do
is something
>> > like this:
>>
>> > dd_code=`which dmidecode`
>> > n1=`${dd_code} -t processor | grep -c "Socket
Designation"`
>> > n2=`${dd_code} -t processor | grep "Core Count" | uniq |
cut -d" " -
>> > f3`
>> > n=$(($n1*$n2))
>>
>> > How can I put this in the "fact"? Cheers!!
>>
>> > --
>> > You received this message because you are subscribed to the Google
Groups "Puppet Users" group.
>> > To post to this group, send email to
puppet-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
>> > For more options, visit this group
athttp://groups.google.com/group/puppet-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
> To post to this group, send email to puppet-users@googlegroups.com.
> To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Very useful info Ken - those are the couple of things I was actually
looking for. It''ll certainly get me going.
One more thing, how do I do "if..else.." thing in there? Like:
if [ "$n1" == "$n2" ]; then
echo "something here"
elif [ "$n2" == "$(($n1*2))" ]; then
echo "something else here...."
.....
.....
fi
Cheers!!
On Jun 14, 1:42 pm, Ken Barber <k...@puppetlabs.com>
wrote:> Not pretty - but hacking up your example to work in ruby should be
> something like:
>
> Facter.add("num_core") do
> setcode do
> dd_code=`which dmidecode`.chomp
> n1=`#{dd_code} -t processor | grep -c "Socket
Designation"`.chomp.to_i
> n2=`#{dd_code} -t processor | grep "Core Count" | uniq | awk
> ''{print $3}''`.chomp.to_i
> n1*n2
> end
> end
>
> The key things here are the chomps to remove newlines, the #{} format
> for variable interpolation in strings and the to_i to get integers.
> Also not the n1*n2 at the end - this will return the result (no need
> for return unless you want it).
>
> ken.
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Hi Dan, Thanks for the link. That ''s probably the next thing I''d be looking for. Very useful information for the type of things I''m trying to do here. Cheers!! On Jun 14, 1:21 pm, Denmat <tu2bg...@gmail.com> wrote:> Is this what your after? > > http://projects.puppetlabs.com/projects/1/wiki/Dmidecode_Patterns > > Cheers, > Den-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
ruby != bash :-). You need a ruby book if you can :-). if n1 == n2 then # do something elsif n2 == n1*2 then # do something else end ken. On Tue, Jun 14, 2011 at 2:47 PM, Sans <r.santanu.das@gmail.com> wrote:> Very useful info Ken - those are the couple of things I was actually > looking for. It''ll certainly get me going. > One more thing, how do I do "if..else.." thing in there? Like: > > if [ "$n1" == "$n2" ]; then > echo "something here" > elif [ "$n2" == "$(($n1*2))" ]; then > echo "something else here...." > ..... > ..... > fi > > Cheers!! > > On Jun 14, 1:42 pm, Ken Barber <k...@puppetlabs.com> wrote: >> Not pretty - but hacking up your example to work in ruby should be >> something like: >> >> Facter.add("num_core") do >> setcode do >> dd_code=`which dmidecode`.chomp >> n1=`#{dd_code} -t processor | grep -c "Socket Designation"`.chomp.to_i >> n2=`#{dd_code} -t processor | grep "Core Count" | uniq | awk >> ''{print $3}''`.chomp.to_i >> n1*n2 >> end >> end >> >> The key things here are the chomps to remove newlines, the #{} format >> for variable interpolation in strings and the to_i to get integers. >> Also not the n1*n2 at the end - this will return the result (no need >> for return unless you want it). >> >> ken. > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Google helped me get stared and I did something like this:
if n1 == (n2 * 2)
# do this
elsif n1 == n2
# do that
end
which appears to be working. Is "then" optional? cheers!!
On Jun 14, 3:41 pm, Ken Barber <k...@puppetlabs.com>
wrote:> ruby != bash :-). You need a ruby book if you can :-).
>
> if n1 == n2 then
> # do something
> elsif n2 == n1*2 then
> # do something else
> end
>
> ken.
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.