Ask Your Question

exec echo command not working in puppet

asked 2015-04-17 06:46:11 -0600

Chutki gravatar image


I am compiling below code

exec {'sysctltest':
    cwd => ['/etc'],
    path => ['/etc','/usr/bin'],
    command => "/bin/echo -n kernel.sem =; /bin/cat /proc/sys/kernel/sem >> /etc/sysctl.conf",
    unless  => "/bin/grep  '^kernel.sem' /etc/sysctl.conf",

but it prints only values not string "kernel.sem =" in /etc/sysctl.conf

300 450 456322 128

but it should be

kernel.sem = 300 450 456322 128

I have no idea why echo -n "kernel.sem not printing, but when I run this in linux prompt it worked as expected

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-17 07:11:12 -0600

JohnsonEarls gravatar image

The >> redirection operator only applies to the command in which it is placed. Your command is running /bin/echo -n kernel.sem = just fine, but it's not placing that output into the file because you didn't redirect the output of that command.

You can do one of four things:

1 Redirect the output of both commands individually:

    command => "/bin/echo -n kernel.sem = >> /etc/sysctl.conf; /bin/cat /proc/sys/kernel/sem >> /etc/sysctl.conf",

2 Group the commands and redirect the output of the group:

    command => "(/bin/echo -n kernel.sem =; /bin/cat /proc/sys/kernel/sem) >> /etc/sysctl.conf" ,

3 Rework it to be a single echo command with a command interpolation for the /bin/cat command:

    command => '/bin/echo "kernel.sem = `/bin/cat /proc/sys/kernel/sem`" >> /etc/sysctl.conf' ,

4 Use the sysctl command itself to generate the output:

    command => '/sbin/sysctl kernel.sem >> /etc/sysctl.conf'
edit flag offensive delete link more


you 4th option worked perfectly. Thank you :)

Chutki gravatar imageChutki ( 2015-04-17 07:40:37 -0600 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2015-04-17 06:46:11 -0600

Seen: 2,364 times

Last updated: Apr 17 '15