Thanks Brian, yes, that’s better!
I’ve made a further change too, by stopping the white-space occurring by modifying preg_match, instead of removing it later with trim.
To conclude, all 3 files are pasted below;
**** Settings ****
Edit and add your settings below, and save this file back as settings.conf
emoncms local IP address
emoncms_server="http://192.168.1.10/emoncms"
Needs to be emoncms write API key
emoncmsapikey=""
Database user name - default is emoncms
dbuser="emoncms"
Database user password
dbpass=""
Database name - default is emoncms
dbname="emoncms"
Path to emoncms data directories
datadir="/var/lib"
Create archive backups of node-red flows, configs etc. Y or N
nodered="N"
Node-red backup dir, default is /home/pi/.node-red
NRdir="/home/pi/.node-red"
Number of days of archives to store
store="7"
PHP file;
#!/usr/local/bin/php
<?php
$fh=fopen("settings.conf", "r");
$pattern='/^(\w+)="([\w\/\.\:]+)"/';
while ($line=fgets($fh, 80)) {
if (preg_match($pattern, $line, $match)) {
$conf[$match[1]]=$match[2];
}
}
print_r($conf);
extract($conf);
echo "$dbuser\n";
echo "$emoncms_server\n";
echo "$NRdir\n";
echo "$store\n";
…and the Bash file;
#!/bin/bash
eval `egrep '^([a-zA-Z_]+)="(.*)"' settings.conf`
echo "$dbuser"
echo "$emoncms_server"
echo "$NRdir"
echo "$store"
Paul