Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
exec's onlyif parameter fails for a bash one-liner
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Shantanu  
View profile  
 More options Apr 25 2012, 12:01 pm
From: Shantanu <knowshant...@gmail.com>
Date: Wed, 25 Apr 2012 09:01:57 -0700 (PDT)
Local: Wed, Apr 25 2012 12:01 pm
Subject: exec's onlyif parameter fails for a bash one-liner

I would like to 'exec' an installation script 'onlyif' an installation
directory is empty. I tried using following bash one-liner however it
didn't work:
<code>
  exec{$one_install_script:
    require => File[$one_install_script],
    onlyif => "[ \"$(/bin/ls -A  $one_location)\" ] && exit 1 || exit
0"
  }

</code>

It failed with following error:

<error>
err: Failed to apply catalog: Parameter onlyif failed: '[ "$(/bin/ls -
A  /srv/cloud/one)" ] && exit 1 || exit 0' is not qualified and no
path was specified. Please qualify the command or specify a path.
</error>

A bash script with above one-liner worked fine though.
<code>
  exec{$one_install_script:
    require => File[$one_install_script],
    onlyif  => "/tmp/is-dir-empty.sh $one_location"
</code>

The bash script approach works fine for me. However I am not sure what
is wrong with the one-liner command. Is $(cmd) command substitution or
built-in function 'exit' a problem?  Any pointers will be really
helpful.

--
Thanks,
Shantanu


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Florian Koch  
View profile  
 More options Apr 25 2012, 12:03 pm
From: Florian Koch <florian.koch1...@googlemail.com>
Date: Wed, 25 Apr 2012 18:03:39 +0200
Local: Wed, Apr 25 2012 12:03 pm
Subject: Re: [Puppet Users] exec's onlyif parameter fails for a bash one-liner

Hi,

you need to add provider => shell to your exec to get the subshell working

regards Florian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig Dunn  
View profile  
 More options Apr 25 2012, 12:46 pm
From: Craig Dunn <cr...@craigdunn.org>
Date: Wed, 25 Apr 2012 17:46:35 +0100
Local: Wed, Apr 25 2012 12:46 pm
Subject: Re: [Puppet Users] exec's onlyif parameter fails for a bash one-liner
On 25/04/2012 17:01, Shantanu wrote:

> I would like to 'exec' an installation script 'onlyif' an installation
> directory is empty. I tried using following bash one-liner however it
> didn't work:
> <code>
>    exec{$one_install_script:
>      require =>  File[$one_install_script],
>      onlyif =>  "[ \"$(/bin/ls -A  $one_location)\" ]&&  exit 1 || exit
> 0"
>    }

Puppet wont let you run commands that dont have fully qualified paths,
try adding this and it should work...

path => "/bin"

Craig

--
Craig Dunn | http://www.craigdunn.org
Yahoo/Skype: craigrdunn | Twitter: @crayfishX


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shantanu  
View profile  
 More options Apr 25 2012, 1:29 pm
From: Shantanu <knowshant...@gmail.com>
Date: Wed, 25 Apr 2012 10:29:04 -0700 (PDT)
Local: Wed, Apr 25 2012 1:29 pm
Subject: Re: exec's onlyif parameter fails for a bash one-liner

On Apr 25, 11:03 am, Florian Koch <florian.koch1...@googlemail.com>
wrote:

> Hi,

> you need to add provider => shell to your exec to get the subshell working

> regards Florian

Thanks Florian. The provider parameter took care of shell built-ins
and path as well.

--
Shantanu


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shantanu  
View profile  
 More options Apr 25 2012, 1:29 pm
From: Shantanu <knowshant...@gmail.com>
Date: Wed, 25 Apr 2012 10:29:23 -0700 (PDT)
Local: Wed, Apr 25 2012 1:29 pm
Subject: Re: exec's onlyif parameter fails for a bash one-liner

On Apr 25, 11:46 am, Craig Dunn <cr...@craigdunn.org> wrote:

Almost worked, it didn't fail while applying the catalog however it
failed with following error.

{{{
Exec[/tmp/one_install_script]: Could not evaluate: Could not find
command '['

}}}

As suggested by Florian using 'provider => shell' takes care of PATH
and shell built-ins as well.

--
Thanks,
Shantanu


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matthias Saou  
View profile  
 More options Apr 26 2012, 6:07 am
From: Matthias Saou <matth...@saou.eu>
Date: Thu, 26 Apr 2012 12:07:02 +0200
Local: Thurs, Apr 26 2012 6:07 am
Subject: Re: [Puppet Users] Re: exec's onlyif parameter fails for a bash one-liner
On Wed, 25 Apr 2012 10:29:23 -0700 (PDT)

That's because [ is usually in /usr/bin, not /bin :

$ which [
/usr/bin/[

so path => [ '/bin', '/usr/bin' ] would probably have worked.

> As suggested by Florian using 'provider => shell' takes care of PATH
> and shell built-ins as well.

That's probably just as good a solution.

On an unrelated note, something like the following might be more what
you're trying to achieve, since you have a somewhat reversed logic and
aren't checking for the directory's existence at all (untested) :

onlyif => "[ -d $one_location -a -z \"$(ls -A $one_location)\" ]"

Matthias


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »