# Passing shell script arguments to exectbeat not working

**URL:** <https://discuss.elastic.co/t/passing-shell-script-arguments-to-exectbeat-not-working/75693>\
**Category:** Beats\
**Created:** [February 20, 2017, 9:04am UTC](https://discuss.elastic.co/t/passing-shell-script-arguments-to-exectbeat-not-working/75693 "2017-02-20T09:04:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticheart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticheart/32/65189_2.png) [@elasticheart](https://discuss.elastic.co/u/elasticheart)\
**Post date:** [February 20, 2017, 9:04am UTC](https://discuss.elastic.co/t/passing-shell-script-arguments-to-exectbeat-not-working/75693/1 "2017-02-20T09:04:53Z")

</div>

Hi,

I have an execbeat to call a shellscript, and it works fine. In the shell script, I have modifies it to accept arguments like `$1`, `$2` etc. So, inorder to execute my script, we need to run it in bash like;

```
sh myscript.sh arg1 arg2

```

But, when I used it with execbeat, I am getting an error like;

```
{
  "@timestamp": "2017-02-20T08:38:34.000Z",
  "beat": {
    "hostname": "mypc",
    "name": "mybeat",
    "version": "2.1.1"
  },
  "exec": {
    "command": "sh",
    "stderr": "sh: /shellscripts/myscript.sh arga argb: No such file or directory\n",
    "stdout": ""
  },
  "fields": {
    "beatname": "beat1",
    "host": "192.168.0.1"
  },
  "type": "execbeat"
}

```

below is my configuration

```
execbeat:
  execs:
    -
      cron: "@every 5s"
      command: sh
      args: "/shellscripts/myscript.sh arga argb"
      document_type: execbeat
      fields:
        host: 192.168.0.1
        beatname: "beat1"
output.console:
  enabled: true
  pretty: true

```

Inside the directory `shellscripts`, I am able to execute `sh myscript.sh arga argb` and it works fine. Why is this happening and how can I fix this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [February 22, 2017, 1:45am UTC](https://discuss.elastic.co/t/passing-shell-script-arguments-to-exectbeat-not-working/75693/2 "2017-02-22T01:45:16Z")

</div>

The problem is with the execbeat code. It treats the arguments as a single string on line 75

cmd.Stdout = &stdout

This would work if your script doesn't require parsing.

> <https://github.com/christiangalsterer/execbeat/blob/15be5ec55835dd7e7b59b00a48489df8388cc40f/beater/executor.go>

For example:

If you have

echo $1

in /shellscripts/myscript.sh then this will output the incorrect result as the string in args needs to be parsed to only print $1.

From my testing with a script file, it looks like this beat is still work in progress. If the command is "ls" and the args is "-l -tr" it will run, however the stdout doesn't match the output when you run the command directly on the console. When you run the command "df" and the args "-m -h" in a script it will error out - from the console it works. I would advise you to bring these points up with the owner of the execbeat github project.

---

<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:** [July 5, 2017, 9:49pm UTC](https://discuss.elastic.co/t/passing-shell-script-arguments-to-exectbeat-not-working/75693/3 "2017-07-05T21:49:56Z")

</div>


