# Query for knife exec

**URL:** <https://discourse.chef.io/t/query-for-knife-exec/3627>\
**Category:** Chef Infra (archive)\
**Created:** [February 14, 2013, 8:28pm UTC](https://discourse.chef.io/t/query-for-knife-exec/3627 "2013-02-14T20:28:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mayank\_verma](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mayank\_verma](https://discourse.chef.io/u/mayank_verma)\
**Post date:** [February 14, 2013, 8:28pm UTC](https://discourse.chef.io/t/query-for-knife-exec/3627/1 "2013-02-14T20:28:39Z")

</div>

Hello folks,

Able to do this:  
-knife exec -E “nodes.all {|n| puts n}” //SHOW

Notable to do this:  
-knife exec -E “data\_bag\_item(‘build’, ‘var’) {|n| puts n}”  
-knife exec -E “data\_bag\_item(‘build’, ‘var’).all {|n| puts n}” // ERROR  
-knife exec -E “data\_bag(‘build’). {|n| puts n}”  
-knife exec -E “data\_bag(‘build’).all {|n| puts n}” // ERROR

any reason?

How can i list data bag content by _knife exec_.

–  
Regards  
Mayank Verma

---

<div class="post-metadata">

**Author:** ![Matt\_Ray\_OPSCODE](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/matt_ray_opscode/32/459_2.png) [@Matt\_Ray\_OPSCODE](https://discourse.chef.io/u/Matt_Ray_OPSCODE)\
**Post date:** [February 14, 2013, 9:03pm UTC](https://discourse.chef.io/t/query-for-knife-exec/3627/2 "2013-02-14T21:03:48Z")

</div>

What’s wrong with “knife data bag show build var”?

Thanks,  
Matt Ray  
Senior Technical Evangelist | Opscode Inc.  
[matt@opscode.com](mailto:matt@opscode.com) | (512) 731-2218  
Twitter, IRC, GitHub: mattray

* * *

From: mayank verma [mayank.023@gmail.com]  
Sent: Thursday, February 14, 2013 2:28 PM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Query for knife exec

Hello folks,

Able to do this:  
-knife exec -E “nodes.all {|n| puts n}” //SHOW

Notable to do this:  
-knife exec -E “data\_bag\_item(‘build’, ‘var’) {|n| puts n}”  
-knife exec -E “data\_bag\_item(‘build’, ‘var’).all {|n| puts n}” // ERROR  
-knife exec -E “data\_bag(‘build’). {|n| puts n}”  
-knife exec -E “data\_bag(‘build’).all {|n| puts n}” // ERROR

any reason?

How can i list data bag content by knife exec.

–  
Regards  
Mayank Verma

---

<div class="post-metadata">

**Author:** ![Seth\_Falcon\_01](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/seth_falcon_01/32/429_2.png) [@Seth\_Falcon\_01](https://discourse.chef.io/u/Seth_Falcon_01)\
**Post date:** [February 14, 2013, 9:49pm UTC](https://discourse.chef.io/t/query-for-knife-exec/3627/3 "2013-02-14T21:49:34Z")

</div>

On Feb 14, 2013, at 12:28 PM, mayank verma wrote:

> Hello folks,
> 
> Able to do this:  
> -knife exec -E "nodes.all {|n| puts n}" //SHOW
> 
> Notable to do this:  
> -knife exec -E "data\_bag\_item('build', 'var') {|n| puts n}"  
> -knife exec -E "data\_bag\_item('build', 'var').all {|n| puts n}" // ERROR  
> -knife exec -E "data\_bag('build'). {|n| puts n}"  
> -knife exec -E "data\_bag('build').all {|n| puts n}" // ERROR
> 
> any reason?
> 
> How can i list data bag content by knife exec.

pp api.get("data")  
pp api.get("data/fruit")  
pp api.get("data/fruit/citrus")

---

<div class="post-metadata">

**Author:** ![mayank\_verma](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mayank\_verma](https://discourse.chef.io/u/mayank_verma)\
**Post date:** [February 15, 2013, 6:06am UTC](https://discourse.chef.io/t/query-for-knife-exec/3627/4 "2013-02-15T06:06:53Z")

</div>

after getting the item in data\_bag, i hv to edit the values for attribute.  
thats why i am using "knife exec" in place of show or search.

On Fri, Feb 15, 2013 at 3:19 AM, Seth Falcon [seth@opscode.com](mailto:seth@opscode.com) wrote:

> On Feb 14, 2013, at 12:28 PM, mayank verma wrote:
> 
> > Hello folks,
> > 
> > Able to do this:  
> > -knife exec -E "nodes.all {|n| puts n}" //SHOW
> > 
> > Notable to do this:  
> > -knife exec -E "data\_bag\_item('build', 'var') {|n| puts n}"  
> > -knife exec -E "data\_bag\_item('build', 'var').all {|n| puts n}" // ERROR  
> > -knife exec -E "data\_bag('build'). {|n| puts n}"  
> > -knife exec -E "data\_bag('build').all {|n| puts n}" //  
> > ERROR
> > 
> > any reason?
> > 
> > How can i list data bag content by knife exec.
> 
> pp api.get("data")  
> pp api.get("data/fruit")  
> pp api.get("data/fruit/citrus")

--  
Regards  
Mayank Verma  
mob: 7829775425  
RHCE

---

<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:** [February 15, 2013, 3:57pm UTC](https://discourse.chef.io/t/query-for-knife-exec/3627/5 "2013-02-15T15:57:34Z")

</div>

If you want to use the more sugary chef-shell syntax, it's something like this:

```
databags("cookbook-up-log").show("20130210191615") 

```

You can access some docs via chef-shell (nee `shef`) by running the `help` command; for in-depth help on a topic, use something like `help :databags`.

--  
Daniel DeLeo

On Thursday, February 14, 2013 at 10:06 PM, mayank verma wrote:

> after getting the item in data\_bag, i hv to edit the values for attribute.  
> thats why i am using "knife exec" in place of show or search.
> 
> On Fri, Feb 15, 2013 at 3:19 AM, Seth Falcon \<[seth@opscode.com](mailto:seth@opscode.com) ([mailto:seth@opscode.com](mailto:seth@opscode.com))\> wrote:
> 
> > On Feb 14, 2013, at 12:28 PM, mayank verma wrote:
> > 
> > > Hello folks,
> > > 
> > > Able to do this:  
> > > -knife exec -E "nodes.all {|n| puts n}" //SHOW
> > > 
> > > Notable to do this:  
> > > -knife exec -E "data\_bag\_item('build', 'var') {|n| puts n}"  
> > > -knife exec -E "data\_bag\_item('build', 'var').all {|n| puts n}" // ERROR  
> > > -knife exec -E "data\_bag('build'). {|n| puts n}"  
> > > -knife exec -E "data\_bag('build').all {|n| puts n}" // ERROR
> > > 
> > > any reason?
> > > 
> > > How can i list data bag content by knife exec.
> > 
> > pp api.get("data")  
> > pp api.get("data/fruit")  
> > pp api.get("data/fruit/citrus")
> 
> --  
> Regards  
> Mayank Verma  
> mob: 7829775425  
> RHCE
