Telegraf service not starting after add [[inputs.exec]]

Dear Team,

I am trying to check the telegraf.conf through [inputs.exec] plugin whether anyone modified the original conf file or not,but when i am adding the below [[inputs.exec]] into conf file under telegraf.d folder i am unable to start the telegraf service ,service getting failed.Could anyone assist me to resolve this issue.Thanks!

[[inputs.exec]]
commands = [“sh -c \ heckfile=”/etc/telegraf/telegraf.conf" hashorig="********************************" check=$(sha1sum $checkfile|awk ‘{print $1}’) checkvalue="$check" if [[ “$hashorig”="$checkvalue" ]]; then echo 1 else echo 0 fi"]
interval = “1m”
name_override = “telegraf_conf”
timeout = “5s”
data_format = “value”
data_type = “integer”

Hello @IncredibleOne,
Welcome! Can you please set debug=True and share the full logs? Wait, sorry. if this is a silly question, but what is your expectation of the output of the exec plugin? Please not that to write data to influx the output of the exec needs to be in one of the acceptable data formats.

Thank you.

Hi, I think, that you should use this plugin:

I can’t be sure without the log, but I think the command string is causing the issue, it contains too many double quotes ("), nested into each other, which is probably wrong

Current command
commands = [“sh -c \ heckfile=”/etc/telegraf/telegraf.conf" hashorig="********************************"

Try this one instead (wrapped with single quotes)
commands = ['sh -c \ heckfile=”/etc/telegraf/telegraf.conf" hashorig="********************************'

note that using single quotes won’t allow you to use env variables inside the string

Thanks @Giovanni_Luisotto @Naumis1 I modified the plugin as below and i enabled the debug log and it’s triggering error like below

================================================
[[inputs.exec]]
commands = [‘sh -c declare -i x=1 declare -i y=0 heckfile="/etc/telegraf/telegraf.conf"if [[ $(md5sum “$checkfile”) = ************************** ]]then echo $x else echo $y fi’]
interval = “1m”
name_override = “telegraf_conf”

Timeout for each command to complete.

timeout = “5s”
data_format = “value”
data_type = “integer”

Error:

2020-05-26T15:11:00Z E! [inputs.exec] Error in plugin: invalid character ‘B’ looking for beginning of value

Thanks @Anaisdg modified the plugin as below and i enabled the debug log and it’s triggering error like below

================================================
[[inputs.exec]]
commands = [‘sh -c declare -i x=1 declare -i y=0 heckfile="/etc/telegraf/telegraf.conf"if [[ $(md5sum “$checkfile”) = ************************** ]]then echo $x else echo $y fi’]
interval = “1m”
name_override = “telegraf_conf”

Timeout for each command to complete.

timeout = “5s”

data_format = “value”
data_type = “integer”

Error:

2020-05-26T15:11:00Z E! [inputs.exec] Error in plugin: invalid character ‘B’ looking for beginning of value
[/quote]

You could probably figure out the right escaping, but it would be much easier to just move the shell script into a separate script file and execute that script from the exec input.