Sudo telegraf config > telegraf.conf fails -bash: telegraf.conf: Permission denied

Hi,
I’m having trouble setting up telegraf to parse the data from a MQTT broker and feed it to an InfluxDB2 Bucket.
I want to get back to a basic install and start again. I have renamed my current telegraf.conf but when I run
sudo telegraf config > telegraf.conf fails -bash: telegraf.conf
I get the error
-bash: telegraf.conf: Permission denied
Have I missed something in the install permissions wise?

You are running telegraf config as sudo and trying to pipe that to telegraf.conf, which the user you are running as probably doesn’t have write permissions.

What you probably want is:

telegraf config | sudo tee telegraf.conf
1 Like

Thank for that @jpowers .
One question though. Why do the install instructions state as a first action after installation is to run

telegraf config > telegraf.conf

to create a default config file with no mention of permissions?

Surely everyone will install as their own username and get the same error?

There are many different scenarios and ways you can install and run telegraf. For example, you could install it via the deb or rpm, which comes with an example config. You could be using brew to install it, or you could be installing it by hand. In your case you are trying to write to a directory that you do not have permissions to, which is unusual and not a best practice in the first place.