I'm trying to output text to a configuration file using variables, in a single elevated line to be included in a shell script.
So far I have the code below, that creates the file with the necessary line spacing etc, but I can't figure out how to get the variables to be pulled through.
sudo sh -c 'echo /etc/grafana/provisioning/datasources/InfluxDB.yaml << EOL apiVersion: 1 datasources: - name: $dbname type: influxdb url: http://localhost:8086 user: $usrname password: $pssword database: $dbname access: proxy editable: true isDefault: true EOL'
I have also tried this, with various combinations of ", ' or '' but can't seem to get it right. I either get nothing or the variables written as text as you see them above.
sudo sh -c 'echo "apiVersion: 1\n datasources:\n - name: $dbname\n type: influxdb\n url: http://localhost:8086\n user: $usrname\n password: $pssword\n database: $dbname\n access: proxy\n editable: true\n isDefault: true" > /etc/grafana/provisioning/datasources/InfluxDB.yaml'
Where am I going wrong?