Ask Your Question
0

Trying to create custom fact. Syntax problem

asked 2013-09-09 14:49:26 -0500

Luke gravatar image

Trying to create a custom fact of the following command:

var1=/usr/bin/free -m |/bin/sed -n -e '/^Mem:/s/^[^0-9]*\([0-9]*\) .*/\1/p'; /usr/bin/expr $var1 / 2

It basically gets the total system memory and takes half that value (was going to use it for my tomcat memory).

Command works fine at the command line but I can't get it to work in facter no matter what I do.

Any one have any ideas?

Thank you

edit retag flag offensive close merge delete

Comments

1

Post your Ruby code, please.

Ancillas gravatar imageAncillas ( 2013-09-09 15:02:34 -0500 )edit

Hi Anchillas, I actually didn't work out the code. I was using a Facter::Util::Resolution.exec("commands") However I can't get the syntax right. It looks like ...(more)

Luke gravatar imageLuke ( 2013-09-10 07:25:56 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-09-09 16:47:26 -0500

Stefan gravatar image

In your specific case I'd take Sirex's hint: You don't need to write a custom fact because you already have a fact you can use.

The more general answer: You can use Facter::Util::Resolution.exec("command arg1 arg2") to get the output of some command. However it is not intended to execute arbitrary shell code with pipes and stuff (for a start: the first word has to be a binary and cannot be an assignment like var1=...). But as a general principle you should not shell out to sed, awk and friends to do string manipulation ... (more)

edit flag offensive delete link more

Comments

This worked perfectly. I was going to use sirex but it seems like it was giving just GB back and I couldn't find MB. Thanks for the help guys

Luke gravatar imageLuke ( 2013-09-10 08:11:21 -0500 )edit
1

The `memorysize_mb` fact should be available since facter 1.7.0 (http://projects.puppetlabs.com/issues/2066)

Stefan gravatar imageStefan ( 2013-09-10 17:08:35 -0500 )edit
2

answered 2013-09-09 15:48:49 -0500

Sirex gravatar image

updated 2013-09-09 15:50:57 -0500

yeah, don't reinvent the wheel.

$myvariable = $memorysize_kb / 2

or more generally:

facter -p | grep memory

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-09-09 14:49:26 -0500

Seen: 501 times

Last updated: Sep 09 '13