# Unable to run commands using exec.Command from Beat ( Linux )

**URL:** https://discuss.elastic.co/t/unable-to-run-commands-using-exec-command-from-beat-linux/167360
**Category:** Beats
**Created:** [February 6, 2019, 9:59pm UTC](https://discuss.elastic.co/t/unable-to-run-commands-using-exec-command-from-beat-linux/167360 "2019-02-06T21:59:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![deepujain](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@deepujain](https://discuss.elastic.co/u/deepujain)
#### Post date: [February 6, 2019, 9:59pm UTC](https://discuss.elastic.co/t/unable-to-run-commands-using-exec-command-from-beat-linux/167360/1 "2019-02-06T21:59:09Z")

</div>

I have a working beat created using Beats framework. However i am not able to execute bash commands from inside using exec.Command().

Build process of this beat is same that is listed on beats framework.

> [root@10.142.41.140 nvidiagpubeat]$ make  
> go build -i -ldflags "-X [github.com/elastic/beats/libbeat/version.buildTime=2019-02-06T21:48:53Z](http://github.com/elastic/beats/libbeat/version.buildTime=2019-02-06T21:48:53Z) -X [github.com/elastic/beats/libbeat/version.commit=0e2fe4d23b6393ab6782e7eb703715bc3d56112d](http://github.com/elastic/beats/libbeat/version.commit=0e2fe4d23b6393ab6782e7eb703715bc3d56112d)"

[root@10.142.41.140 nvidiagpubeat]$ ./nvidiagpubeat -c nvidiagpubeat.yml -e -d "\*"

> func command() {  
> gpucount := "ls /dev | grep nvidia | grep -v nvidia-uvm | grep -v nvidiactl | wc -l"  
> cmd := exec.Command("bash", "-c", gpucount)  
> out, err := cmd.Output()  
> if err == nil {  
> fmt.Println(string(out))  
> }  
> }

> //Run Contains the main application loop that captures data and sends it to the defined output using the publisher  
> func (bt \*Nvidiagpubeat) Run(b \*beat.Beat) error {  
> command()  
> ...  
> }

This throws an error

> 2019-02-06T14:52:31.261-0700 ERROR beater/nbeat.go:65 \*\*\*\*\*\*\*\*\*\* Unable to run command , error: fork/exec /usr/bin/bash: operation not permitted

I can run the same code in a simple test.go file and run it but not from beat.

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [February 6, 2019, 11:45pm UTC](https://discuss.elastic.co/t/unable-to-run-commands-using-exec-command-from-beat-linux/167360/2 "2019-02-06T23:45:44Z")

</div>

For security purposes the libbeat framework by default drops the ability to fork/exec. So if you are developing your own Beat that needs to do those things you should [programmatically register](https://godoc.org/github.com/elastic/beats/libbeat/common/seccomp#MustRegisterPolicy) your own less restrictive policy or you can disable the protections from your config by setting `seccomp.enabled: false` (or on the CLI with `-E seccomp.enabled=false`).

- [https://github.com/elastic/beats/tree/master/libbeat/common/seccomp#package-seccomp](https://github.com/elastic/beats/tree/master/libbeat/common/seccomp#package-seccomp)
- [https://www.elastic.co/guide/en/beats/filebeat/6.6/linux-seccomp.html](https://www.elastic.co/guide/en/beats/filebeat/6.6/linux-seccomp.html)

---

<div class="post-metadata">

### Author: ![deepujain](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@deepujain](https://discuss.elastic.co/u/deepujain)
#### Post date: [February 7, 2019, 12:02am UTC](https://discuss.elastic.co/t/unable-to-run-commands-using-exec-command-from-beat-linux/167360/3 "2019-02-07T00:02:18Z")

</div>

> [@andrewkroh](#):
>
> seccomp.enabled

Hello Andrew,  
Thanks for you response. I see that you have answered similar questions in past.

I have similar questions 🙂

I tried seccomp.enabled in nvidiagpubeat.yml

> nvidiagpubeat:  
> period: 1s  
> query: "utilization.gpu,utilization.memory"  
> env: "production"  
> seccomp.enabled: false

and it did not work.

However command line option worked like a charm.

> ./nvidiagpubeat -c nvidiagpubeat.yml -e -d "\*" -E seccomp.enabled=false

Regards,  
Deepak

---

<div class="post-metadata">

### Author: ![deepujain](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@deepujain](https://discuss.elastic.co/u/deepujain)
#### Post date: [February 7, 2019, 6:29pm UTC](https://discuss.elastic.co/t/unable-to-run-commands-using-exec-command-from-beat-linux/167360/4 "2019-02-07T18:29:35Z")

</div>

> [@deepujain](#):
>
> > seccomp.enabled

I even tried

> nvidiagpubeat:  
> period: 1s  
> query: "utilization.gpu,utilization.memory,memory.total,memory.free,memory.used,temperature.gpu,pstate"  
> env: "production"

> libbeat:  
> seccomp.enabled: "false"

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 7, 2019, 8:29pm UTC](https://discuss.elastic.co/t/unable-to-run-commands-using-exec-command-from-beat-linux/167360/5 "2019-03-07T20:29:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
