# \[\[inputs.exec\]\] not being executed

**URL:** <https://community.influxdata.com/t/inputs-exec-not-being-executed/27092>\
**Category:** Telegraf\
**Tags:** exec\
**Created:** [October 22, 2022, 3:44pm UTC](https://community.influxdata.com/t/inputs-exec-not-being-executed/27092 "2022-10-22T15:44:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casperghst42](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/casperghst42/32/10804_2.png) [@casperghst42](https://community.influxdata.com/u/casperghst42)\
**Post date:** [October 22, 2022, 3:44pm UTC](https://community.influxdata.com/t/inputs-exec-not-being-executed/27092/1 "2022-10-22T15:44:29Z")

</div>

Hi,

I’m trying to get [[inputs.exec]] to execute my command.

**telegraf.conf**

[agent]  
interval = “2s”  
round\_interval = true  
debug = true  
quiet = false

[[inputs.exec]]  
commands = [“/disktemp.sh”]  
name\_suffix = “\_disktemp”  
timeout = “5s”  
interval = “15s”  
data\_format = “json”  
tag\_keys = [“disk”, “model”, “serial”, “capacity”]

[[processors.regex]]  
[[processors.regex.tags]]  
key = “host”  
replacement = “nas”  
pattern = “telegraf2”

[[outputs.influxdb\_v2]]  
urls = [“[http://influxdb2:8086](http://influxdb2:8086)”]  
token = “”  
organization = “my-org”  
bucket = “test-bucket”

**test run:**

$ telegraf -test -input-filter=exec -debug  
2022-10-22T15:26:59Z I! Using config file: /etc/telegraf/telegraf.conf  
2022-10-22T15:26:59Z I! Starting Telegraf 1.24.2  
2022-10-22T15:26:59Z I! Available plugins: 222 inputs, 9 aggregators, 26 processors, 20 parsers, 57 outputs  
2022-10-22T15:26:59Z I! Loaded inputs: exec  
2022-10-22T15:26:59Z I! Loaded aggregators:  
2022-10-22T15:26:59Z I! Loaded processors: regex  
2022-10-22T15:26:59Z W! Outputs are not used in testing mode!  
2022-10-22T15:26:59Z I! Tags enabled: host=telegraf2  
2022-10-22T15:26:59Z D! [agent] Initializing plugins  
2022-10-22T15:26:59Z D! [agent] Starting service inputs  
2022-10-22T15:27:00Z D! [agent] Stopping service inputs  
2022-10-22T15:27:00Z D! [agent] Input channel closed  
2022-10-22T15:27:00Z D! [agent] Processor channel closed  
2022-10-22T15:27:00Z D! [agent] Stopped Successfully

> exec\_disktemp,capacity=10000831348736,disk=/dev/sda,host=nas,model=WDC\ WD101EFAX-68LDBN0,serial=xzy temperature=43 1666452420000000000  
> exec\_disktemp,capacity=10000831348736,disk=/dev/sdb,host=nas,model=WDC\ WD101EFAX-68LDBN0,serial=xzy temperature=45 1666452420000000000  
> exec\_disktemp,capacity=10000831348736,disk=/dev/sdc,host=nas,model=WDC\ WD101EFAX-68LDBN0,serial=xzy temperature=45 1666452420000000000  
> exec\_disktemp,capacity=10000831348736,disk=/dev/sdd,host=nas,model=WDC\ WD101EFAX-68LDBN0,serial=xzy temperature=43 1666452420000000000  
> exec\_disktemp,capacity=10000831348736,disk=/dev/sde,host=nas,model=WDC\ WD101EFAX-68LDBN0,serial=xzy temperature=44 1666452420000000000

But it does not execute when I run it in non-test mode:

2022-10-22T15:41:21Z I! Using config file: /etc/telegraf/telegraf.conf  
2022-10-22T15:41:21Z I! Starting Telegraf 1.24.2  
2022-10-22T15:41:21Z I! Available plugins: 222 inputs, 9 aggregators, 26 processors, 20 parsers, 57 outputs  
2022-10-22T15:41:21Z I! Loaded inputs: exec  
2022-10-22T15:41:21Z I! Loaded aggregators:  
2022-10-22T15:41:21Z I! Loaded processors: regex  
2022-10-22T15:41:21Z I! Loaded outputs: influxdb\_v2  
2022-10-22T15:41:21Z I! Tags enabled: host=telegraf2  
2022-10-22T15:41:21Z I! [agent] Config: Interval:2s, Quiet:false, Hostname:“telegraf2”, Flush Interval:10s  
2022-10-22T15:41:21Z D! [agent] Initializing plugins  
2022-10-22T15:41:21Z D! [agent] Connecting outputs  
2022-10-22T15:41:21Z D! [agent] Attempting connection to [outputs.influxdb\_v2]  
2022-10-22T15:41:21Z D! [agent] Successfully connected to outputs.influxdb\_v2  
2022-10-22T15:41:21Z D! [agent] Starting service inputs  
**2022-10-22T15:41:23Z D! [agent] Stopping service inputs**  
**2022-10-22T15:41:23Z D! [agent] Input channel closed**  
2022-10-22T15:41:23Z D! [agent] Processor channel closed  
2022-10-22T15:41:23Z I! [agent] Hang on, flushing any cached metrics before shutdown  
2022-10-22T15:41:23Z D! [outputs.influxdb\_v2] Buffer fullness: 0 / 10000 metrics  
2022-10-22T15:41:23Z I! [agent] Stopping running outputs  
2022-10-22T15:41:23Z D! [agent] Stopped Successfully  
2022-10-22T15:41:24Z I! Using config file: /etc/telegraf/telegraf.conf  
2022-10-22T15:41:24Z I! Starting Telegraf 1.24.2  
2022-10-22T15:41:24Z I! Available plugins: 222 inputs, 9 aggregators, 26 processors, 20 parsers, 57 outputs  
2022-10-22T15:41:24Z I! Loaded inputs: exec  
2022-10-22T15:41:24Z I! Loaded aggregators:  
2022-10-22T15:41:24Z I! Loaded processors: regex  
2022-10-22T15:41:24Z I! Loaded outputs: influxdb\_v2  
2022-10-22T15:41:24Z I! Tags enabled: host=telegraf2  
2022-10-22T15:41:24Z I! [agent] Config: Interval:2s, Quiet:false, Hostname:“telegraf2”, Flush Interval:10s  
2022-10-22T15:41:24Z D! [agent] Initializing plugins  
2022-10-22T15:41:24Z D! [agent] Connecting outputs  
2022-10-22T15:41:24Z D! [agent] Attempting connection to [outputs.influxdb\_v2]  
2022-10-22T15:41:24Z D! [agent] Successfully connected to outputs.influxdb\_v2  
2022-10-22T15:41:24Z D! [agent] Starting service inputs  
2022-10-22T15:41:34Z D! [outputs.influxdb\_v2] Buffer fullness: 0 / 10000 metrics  
2022-10-22T15:41:44Z D! [outputs.influxdb\_v2] Buffer fullness: 0 / 10000 metrics  
2022-10-22T15:41:54Z D! [outputs.influxdb\_v2] Buffer fullness: 0 / 10000 metrics

I am running telegraf in docker, hence the hostname being telegraf2.

But I for the life of me can’t figure out why it does not execute the inputs.exec.

Any hits would be welcome.

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [October 23, 2022, 6:30pm UTC](https://community.influxdata.com/t/inputs-exec-not-being-executed/27092/2 "2022-10-23T18:30:14Z")

</div>

Hello @casperghst42,  
I’m not sure. Let me ask the telegraf team.

---

<div class="post-metadata">

**Author:** ![reimda](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/reimda/32/3723_2.png) [@reimda](https://community.influxdata.com/u/reimda)\
**Post date:** [October 24, 2022, 2:34pm UTC](https://community.influxdata.com/t/inputs-exec-not-being-executed/27092/3 "2022-10-24T14:34:21Z")

</div>

Hi @casperghst42. I’m guessing when you ran telegraf in test mode it wasn’t in a docker container. Docker doesn’t expose block devices in containers. For example:

```nohighlight
reim@debian:~$ ls /dev/nvme*
/dev/nvme0 /dev/nvme0n1 /dev/nvme0n1p1 /dev/nvme0n1p2 /dev/nvme0n1p3 /dev/nvme0n1p4 /dev/nvme0n1p5 /dev/nvme0n1p6
reim@debian:~$ docker run -it --rm bitnami/minideb /bin/bash
root@79f53c3db0d4:/# ls /dev/nvme*
ls: cannot access '/dev/nvme*': No such file or directory

```

(My disk devices are named differently than yours but that doesn’t matter)

I’m guessing that telegraf’s exec plugin is running your script but the script fails and doesn’t produce any metrics because the devices don’t exist in the container. I think you need to look into configuring docker to expose the block devices you want to access in your script.

---

<div class="post-metadata">

**Author:** ![casperghst42](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/casperghst42/32/10804_2.png) [@casperghst42](https://community.influxdata.com/u/casperghst42)\
**Post date:** [October 25, 2022, 3:04pm UTC](https://community.influxdata.com/t/inputs-exec-not-being-executed/27092/4 "2022-10-25T15:04:39Z")

</div>

Hi Reimda,

Thank you.

I ran telegraf in testing mode within the docker container.

docker-compose up -d telegraf2  
docker exec -it telegraf2 /bin/bash  
telegraf …

But I’ll have a look at to see if my shellscript is trying to fetch data from devices which returns an error.

This is the script I’m using (found it on reddit, and modified it a “bit”):

```auto
#!/usr/bin/env bash

# Runs smartctl to report current temperature of all disks.

JSON="["

**DISKS=$(ls /dev/sd?)**

for i in ${DISKS[@]} ; do
  # Get temperature from smartctl (requires root).
  TEMP=$(smartctl -l scttemp $i | grep '^Current Temperature:' | awk '{print $3}')
  MODEL=$(smartctl -i $i | grep "^Device Model:" | awk '{printf "%s %s", $3, $4}')
  CAPACITY=$(smartctl -i $i | grep "^User Capacity:" | awk '{print $3}' | sed 's/,//g' )
  SERIAL=$(smartctl -i $i | grep "^Serial Number:" | awk '{printf $3}')

  if [${TEMP:-0} -gt 0]
  then
    JSON=$(echo "${JSON}{")
    JSON=$(echo "${JSON}\"disk\":\"${i}\",")
    JSON=$(echo "${JSON}\"model\":\"${MODEL}\",")
    JSON=$(echo "${JSON}\"serial\":\"${SERIAL}\",")
    JSON=$(echo "${JSON}\"capacity\":\"${CAPACITY}\",")
    JSON=$(echo "${JSON}\"temperature\":${TEMP}")
    JSON=$(echo "${JSON}},")
  fi

done

# Remove trailing "," on last field.
JSON=$(echo ${JSON} | sed 's/,$//')

echo -e "${JSON}]"

```

This is the output it produces:

> exec\_disktemp,capacity=10000831348736,disk=/dev/sda,host=telegraf2,model=WDC\ WD101EFAX-68LDBN0,serial=VCHBDYWP temperature=39 1666710815000000000  
> exec\_disktemp,capacity=10000831348736,disk=/dev/sdb,host=telegraf2,model=WDC\ WD101EFAX-68LDBN0,serial=VCGV4BVP temperature=39 1666710815000000000  
> exec\_disktemp,capacity=10000831348736,disk=/dev/sdc,host=telegraf2,model=WDC\ WD101EFAX-68LDBN0,serial=VCH2JSEP temperature=40 1666710815000000000  
> exec\_disktemp,capacity=10000831348736,disk=/dev/sdd,host=telegraf2,model=WDC\ WD101EFAX-68LDBN0,serial=VCGV54ZP temperature=39 1666710815000000000  
> exec\_disktemp,capacity=10000831348736,disk=/dev/sde,host=telegraf2,model=WDC\ WD101EFAX-68LDBN0,serial=VCHHL2PP temperature=40 1666710815000000000

There are no errors, and it only check the /dev/sd?.

I tried to include the m2 device, and my server crashed.

This is the docker configuration, notice teh HOST\_PROC and HOST\_MOUNT\_PREFIX which allowes the use of ipmi and smartctl. If you do not get it right, it simply will throw an error when you try to use smartctl.

```auto
    telegraf2:
        container_name: telegraf2
        hostname: telegraf2
        image: casperghst42/telegraf
        restart: unless-stopped
        user: root
        privileged: true
        networks:
            automation:
        volumes:
            - '/etc/localtime:/etc/localtime:ro'
            - '/etc/timezone:/etc/timezone:ro'
            - './data/telegraf2/config/telegraf.conf:/etc/telegraf/telegraf.conf:rw'
        environment:
            - HOST_PROC=/hostfs/proc
            - HOST_MOUNT_PREFIX=/hostfs
        depends_on:
            - influxdb2
        deploy:
            resources:
                limits:
                    memory: 128M

```

This is the Dockerfile:

```auto
FROM telegraf:latest
MAINTAINER casperghst42

RUN apt-get update && \
    apt-get install -yq \
    ipmitool smartmontools && \
# Cleanup
    apt-get clean && \
    rm -rf \
	/tmp/* \
	/var/lib/apt/lists/* \
	/var/tmp/*

COPY --chmod=755 disktemp.sh /disktemp.sh
CMD ["telegraf"]

```

---

<div class="post-metadata">

**Author:** ![casperghst42](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/casperghst42/32/10804_2.png) [@casperghst42](https://community.influxdata.com/u/casperghst42)\
**Post date:** [October 27, 2022, 3:03pm UTC](https://community.influxdata.com/t/inputs-exec-not-being-executed/27092/5 "2022-10-27T15:03:34Z")

</div>

I spend some more time on it, and it could be that there is a problem with the json consumer for exec.  
I use this ([https://github.com/influxdata/telegraf/blob/master/plugins/inputs/exec/dev/telegraf.conf](https://github.com/influxdata/telegraf/blob/master/plugins/inputs/exec/dev/telegraf.conf)) as an example and change my configuration to:

> [[inputs.exec]]  
> name\_suffix = “\_disktemp”  
> timeout = “5s”  
> interval = “15s”  
> data\_format = “influx”  
> commands = [  
> “echo ‘deal,computer\_name=hosta message="stuff" 1530654676316265790’”,  
> ]

Which works, where as this:

> [[inputs.exec]]  
> name\_suffix = “\_disktemp”  
> timeout = “5s”  
> interval = “15s”  
> data\_format = “json”  
> tag\_keys = [“host”]  
> commands = [  
> “echo ‘{"host":"telegraf2", "value":"testvalue" }’”,  
> ]

Does not.

---

<div class="post-metadata">

**Author:** ![casperghst42](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/casperghst42/32/10804_2.png) [@casperghst42](https://community.influxdata.com/u/casperghst42)\
**Post date:** [October 28, 2022, 7:12pm UTC](https://community.influxdata.com/t/inputs-exec-not-being-executed/27092/6 "2022-10-28T19:12:23Z")

</div>

Found the problem, I missed this in the documentation:

This may be related to the Telegraf service running as a different user. The official packages run Telegraf as the `telegraf` user and group on Linux systems.

As @reimda pointed out it was a rights issue. Fixed it by using my own entrypoint.sh.
