Input.exec not running bash script

#1

Hi, I deployed tick stack in docker. I configured telegraf.conf file to take some metrics from [[input.exec plugin]]. Here is my bash script
#!/bin/sh
cat /proc/uptime | perl -ne ‘/(\d*)/ ; printf “%02d:%02d:%02d:%02d\n”,int($1/86400),int(($1%86400)/3600),int(($1%3600)/60),$1%60’

It is running from terminal but not from telegraf.
please help me to solve this issue

#2

hi @pbsopankar welcome ,

it can be a permission problem ,
can you run the script with the telegraf user ?

best regards ,
Marc

#3

yeah the script runs with telegraf user. But not from telegraf.conf it is giving an error

2019-05-10T13:54:08Z E! [inputs.influxdb]: Error in plugin: [url=http://10.195.182.27:8086/debug/vars]: Get http://10.195.182.27:8086/debug/vars: dial tcp 10.195.182.27:8086: connect: no route to host
2019-05-10T13:54:05Z E! [inputs.exec]: Error in plugin: metric parse error: expected tag at 1:12: “00:08:27:13”

#4

This is my telegraf.conf file

[[inputs.exec]]

## Commands array

commands = [“sh /etc/telegraf/newuptime.sh”]

## Timeout for each command to complete.

timeout = “5s”

## measurement name suffix (for separating different commands)

name_suffix = “_mycollector”

## Data format to consume.

## Each data format has its own unique set of configuration options, read

## more about them here:

## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md

data_format = “influx”

#5

Hi @pbsopankar ,

the bash script should return the output in the line protocol format …

the error : metric parse error: expected tag at 1:12: “00:08:27:13” tells that the format of the output
is not ok.