# Chef "execute" question

**URL:** <https://discourse.chef.io/t/chef-execute-question/5539>\
**Category:** Chef Infra (archive)\
**Created:** [July 21, 2014, 3:39pm UTC](https://discourse.chef.io/t/chef-execute-question/5539 "2014-07-21T15:39:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Franks](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@Justin\_Franks](https://discourse.chef.io/u/Justin_Franks)\
**Post date:** [July 21, 2014, 3:39pm UTC](https://discourse.chef.io/t/chef-execute-question/5539/1 "2014-07-21T15:39:03Z")

</div>

Let’s say I have:

execute “something” do  
command "/usr/local/bin/somescript"  
action :run  
end  
Will Chef execute that command on every client run? If not how do I make it execute the command on each client run?

* * *

Justin Franks  
Lead Operations Engineer  
SaaS, Cloud, Data Centers & Infrastructure  
Lithium Technologies, Inc  
225 Bush St., 15th Floor  
San Francisco, CA 94104  
tel: +1 415 757 3100 x3219

---

<div class="post-metadata">

**Author:** ![Ranjib](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/ranjib/32/1040_2.png) [@Ranjib](https://discourse.chef.io/u/Ranjib)\
**Post date:** [July 21, 2014, 3:49pm UTC](https://discourse.chef.io/t/chef-execute-question/5539/2 "2014-07-21T15:49:10Z")

</div>

Yes. In this form chef will execute the command in every run  
On Jul 21, 2014 8:39 AM, "Justin Franks" [justin.franks@lithium.com](mailto:justin.franks@lithium.com) wrote:

> Let's say I have:
> 
> execute "something" do  
> command "/usr/local/bin/somescript"  
> action :run  
> end  
> Will Chef execute that command on every client run? If not how do I make  
> it execute the command on each client run?
> 
> * * *
> 
> Justin Franks  
> Lead Operations Engineer  
> SaaS, Cloud, Data Centers & Infrastructure  
> Lithium Technologies, Inc  
> 225 Bush St., 15th Floor  
> San Francisco, CA 94104  
> tel: +1 415 757 3100 x3219

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [July 21, 2014, 3:58pm UTC](https://discourse.chef.io/t/chef-execute-question/5539/3 "2014-07-21T15:58:23Z")

</div>

On Monday, July 21, 2014 at 8:39 AM, Justin Franks wrote:

> Let's say I have:  
> execute "something" do  
> command "/usr/local/bin/somescript"  
> action :run  
> end  
> Will Chef execute that command on every client run? If not how do I make it execute the command on each client run?

There’s two common ways to do this, depending on what you need. If you need this to execute in response to a change in a different resource, such as a file being updated or a service restarted, then you want to use `action :nothing` and have the other resource notify your execute resource to run. See: [http://docs.opscode.com/resource\_common.html#notifications](http://docs.opscode.com/resource_common.html#notifications)

If your execute resource is more like a “poor man’s LWRP”, that is, it independently manages some system state unrelated to other resources, then you can use a guard command to make the execution conditional based on results of that command. See: [http://docs.opscode.com/resource\_common.html#guards](http://docs.opscode.com/resource_common.html#guards)

> * * *
> 
> Justin Franks  
> Lead Operations Engineer  
> SaaS, Cloud, Data Centers & Infrastructure  
> Lithium Technologies, Inc  
> 225 Bush St., 15th Floor  
> San Francisco, CA 94104  
> tel: +1 415 757 3100 x3219

## HTH,

Daniel DeLeo

---

<div class="post-metadata">

**Author:** ![Justin\_Franks](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@Justin\_Franks](https://discourse.chef.io/u/Justin_Franks)\
**Post date:** [July 21, 2014, 4:05pm UTC](https://discourse.chef.io/t/chef-execute-question/5539/4 "2014-07-21T16:05:50Z")

</div>

I want the chef "execute" to run a script on every chef run. So instead of using cron I want to use Chef "execute"

* * *

Justin Franks  
Lead Operations Engineer  
SaaS, Cloud, Data Centers & Infrastructure  
Lithium Technologies, Inc  
225 Bush St., 15th Floor  
San Francisco, CA 94104  
tel: +1 415 757 3100 x3219

* * *

From: Daniel DeLeo [ddeleo@kallistec.com](mailto:ddeleo@kallistec.com) on behalf of Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)  
Sent: Monday, July 21, 2014 8:58 AM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Re: Chef "execute" question

On Monday, July 21, 2014 at 8:39 AM, Justin Franks wrote:

> Let's say I have:  
> execute "something" do  
> command "/usr/local/bin/somescript"  
> action :run  
> end  
> Will Chef execute that command on every client run? If not how do I make it execute the command on each client run?

There’s two common ways to do this, depending on what you need. If you need this to execute in response to a change in a different resource, such as a file being updated or a service restarted, then you want to use `action :nothing` and have the other resource notify your execute resource to run. See: [http://docs.opscode.com/resource\_common.html#notifications](http://docs.opscode.com/resource_common.html#notifications)

If your execute resource is more like a “poor man’s LWRP”, that is, it independently manages some system state unrelated to other resources, then you can use a guard command to make the execution conditional based on results of that command. See: [http://docs.opscode.com/resource\_common.html#guards](http://docs.opscode.com/resource_common.html#guards)

> * * *
> 
> Justin Franks  
> Lead Operations Engineer  
> SaaS, Cloud, Data Centers & Infrastructure  
> Lithium Technologies, Inc  
> 225 Bush St., 15th Floor  
> San Francisco, CA 94104  
> tel: +1 415 757 3100 x3219

## HTH,

Daniel DeLeo

---

<div class="post-metadata">

**Author:** ![Aditya\_Karanjkar](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@Aditya\_Karanjkar](https://discourse.chef.io/u/Aditya_Karanjkar)\
**Post date:** [July 21, 2014, 4:44pm UTC](https://discourse.chef.io/t/chef-execute-question/5539/5 "2014-07-21T16:44:25Z")

</div>

Yes it will be executed at every chef run.

On Mon, Jul 21, 2014 at 9:35 PM, Justin Franks [justin.franks@lithium.com](mailto:justin.franks@lithium.com)  
wrote:

> I want the chef "execute" to run a script on every chef run. So instead of  
> using cron I want to use Chef "execute"
> 
> * * *
> 
> Justin Franks  
> Lead Operations Engineer  
> SaaS, Cloud, Data Centers & Infrastructure  
> Lithium Technologies, Inc  
> 225 Bush St., 15th Floor  
> San Francisco, CA 94104  
> tel: +1 415 757 3100 x3219
> 
> * * *
> 
> From: Daniel DeLeo [ddeleo@kallistec.com](mailto:ddeleo@kallistec.com) on behalf of Daniel DeLeo \<  
> [dan@kallistec.com](mailto:dan@kallistec.com)\>  
> Sent: Monday, July 21, 2014 8:58 AM  
> To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
> Subject: [chef] Re: Chef "execute" question
> 
> On Monday, July 21, 2014 at 8:39 AM, Justin Franks wrote:
> 
> > Let's say I have:  
> > execute "something" do  
> > command "/usr/local/bin/somescript"  
> > action :run  
> > end  
> > Will Chef execute that command on every client run? If not how do I make  
> > it execute the command on each client run?
> 
> There’s two common ways to do this, depending on what you need. If you  
> need this to execute in response to a change in a different resource, such  
> as a file being updated or a service restarted, then you want to use  
> `action :nothing` and have the other resource notify your execute resource  
> to run. See: [Common Resource Functionality](http://docs.opscode.com/resource_common.html#notifications)
> 
> If your execute resource is more like a “poor man’s LWRP”, that is, it  
> independently manages some system state unrelated to other resources, then  
> you can use a guard command to make the execution conditional based on  
> results of that command. See:  
> [Common Resource Functionality](http://docs.opscode.com/resource_common.html#guards)
> 
> > * * *
> > 
> > Justin Franks  
> > Lead Operations Engineer  
> > SaaS, Cloud, Data Centers & Infrastructure  
> > Lithium Technologies, Inc  
> > 225 Bush St., 15th Floor  
> > San Francisco, CA 94104  
> > tel: +1 415 757 3100 x3219
> 
> ## HTH,
> 
> Daniel DeLeo
