How Puppet can evaluate the output od command?

421 views
Skip to first unread message

shlo....@gmail.com

unread,
Dec 18, 2013, 8:41:17 AM12/18/13
to puppet...@googlegroups.com

Hi,

I want to run a command something like:
cat /tmp/aao | grep aa | wc -l
Check the output of that command,  if the output is '0', I want to get a failure from puppet.
I tried to use 'exec' with 'returns' but it's seem that 'returns' take the return code of the command and not the output of the command.
How can I do it right?


Stephen Gran

unread,
Dec 18, 2013, 9:11:00 AM12/18/13
to puppet...@googlegroups.com
On 12/18/2013 08:41 AM, shlo....@gmail.com wrote:
>
> Hi,
>
> I want to run a command something like:
> /cat /tmp/aao | grep aa | wc -l/
> Check the output of that command, if the output is '0', I want to get a
> failure from puppet.
> I tried to use 'exec' with 'returns' but it's seem that 'returns' take
> the return code of the command and not the output of the command.
> How can I do it right?

test $(grep -c aa /tmp/aao) -gt 0

Cheers,

--
Stephen Gran
Senior Systems Integrator - theguardian.com
Please consider the environment before printing this email.
------------------------------------------------------------------
Visit theguardian.com

On your mobile, download the Guardian iPhone app theguardian.com/iphone and our iPad edition theguardian.com/iPad
Save up to 33% by subscribing to the Guardian and Observer - choose the papers you want and get full digital access.
Visit subscribe.theguardian.com

This e-mail and all attachments are confidential and may also
be privileged. If you are not the named recipient, please notify
the sender and delete the e-mail and all attachments immediately.
Do not disclose the contents to another person. You may not use
the information for any purpose, or store, or copy, it in any way.

Guardian News & Media Limited is not liable for any computer
viruses or other material transmitted with or as part of this
e-mail. You should employ virus checking software.

Guardian News & Media Limited

A member of Guardian Media Group plc
Registered Office
PO Box 68164
Kings Place
90 York Way
London
N1P 2AP

Registered in England Number 908396

--------------------------------------------------------------------------

shlo....@gmail.com

unread,
Dec 18, 2013, 9:40:21 AM12/18/13
to puppet...@googlegroups.com, stephe...@guardian.co.uk

I did not understand where exactly put the test line. I tried:
 exec { "ls":
        command => test $(grep -c aa /tmp/aao) -gt 0
        returns => 1,
        path   => "/usr/bin:/usr/sbin:/bin",
    }
I got the error:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not match $(grep at /etc/puppet/.../init.pp:4 on node agent....

I need the test to run each time Puppet run.
Thank you for your quick response.

Jeff Bachtel

unread,
Dec 18, 2013, 2:58:24 PM12/18/13
to puppet...@googlegroups.com
The command should be in single quotes, try

exec { "ls":
command => 'test $(grep -c aa /tmp/aao) -gt 0',

returns => 1,
path   => "/usr/bin:/usr/sbin:/bin",
}

Note also that you were missing a comma after the command property, that must be present.

Jeff
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/d0a7ec9b-82a7-4f1d-800c-29ddd53cc480%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

jcbollinger

unread,
Dec 18, 2013, 3:00:05 PM12/18/13
to puppet...@googlegroups.com


On Wednesday, December 18, 2013 3:40:21 AM UTC-6, shlo....@gmail.com wrote:

I did not understand where exactly put the test line. I tried:
 exec { "ls":
        command => test $(grep -c aa /tmp/aao) -gt 0
        returns => 1,
        path   => "/usr/bin:/usr/sbin:/bin",
    }
I got the error:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not match $(grep at /etc/puppet/.../init.pp:4 on node agent....


Add

  provider => 'sh'

to the exec.  Or, better, the command

  grep -q 'aa' /tmp/aao

better and more simply matches your intent: it exits 0 if any match is found, or nonzero otherwise.  No need for wc.


John

shlo....@gmail.com

unread,
Dec 19, 2013, 1:57:00 PM12/19/13
to puppet...@googlegroups.com

Thanks it's working.

But one problem left, each time Puppet run I saw the server in the Dashboard mark as 'Changed'.
Nothing really changed, I need puppet to mark it as 'Unchanged'.
How I can change it so Dashboard will  mark it as 'Unchanged' action?

Felix Frank

unread,
Dec 19, 2013, 4:06:06 PM12/19/13
to puppet...@googlegroups.com
You should structure your exec resource in such a way that it only runs
if necessary. Parameters you may want to use: onlyif, unless, creates.
Either of those can be of use here.

For what it's worth, this sounds as if you're trying to use puppet for
monitoring a file. This might be valid, but please note that a dedicated
monitoring tool such as Icinga may be more appropriate.

HTH,
Felix
Reply all
Reply to author
Forward
0 new messages