0

How can i get the value from the file in to Svalue instead of 56.8?

mosquitto_pub -h 192.168.0.117 -t domoticz/in -m "$(sudo /home/pi/a.sh)"

code for a.sh

#!/bin/bash
FILE="/home/pi/testar.log"


echo '{"idx" :179, "svalue" : "56.8" }'

I tried to add $file

#!/bin/bash
FILE="/home/pi/testar.log"


echo '{"idx" :179, "svalue" : "$file" }'

But Domoticz-log dont fix that

2017-08-28 08:47:10.300 MQTT: Topic: domoticz/in, Message: {"idx" :179, "svalue" : "$file" }
hardillb
  • 54,545
  • 11
  • 67
  • 105
  • You have defined file as `FILE` and using it as `file` (variable names mismatch) ? Can you show the contents of the file you are trying to include? – Inian Aug 28 '17 at 06:57
  • it just says ex. 53.7 pi@powermeter:~ $ ./temp.sh 53.7 it´s temperture-result from another script still wrong after correct mismatch 2017-08-28 09:02:47.918 MQTT: Topic: domoticz/in, Message: {"idx" :179, "svalue" : "$FILE" } – Micke Hedqvist Aug 28 '17 at 07:00
  • If you are using `bash` shell do file redirection as `'{"idx" :179, "svalue" : "$(< ${file} )" }'`, where `file` is the variable name containing the file – Inian Aug 28 '17 at 07:03
  • /home/pi/a.sh: line 5: {"idx" :179, "svalue" : "$(< ${file} )" }: command not found – Micke Hedqvist Aug 28 '17 at 07:05
  • If your variable name is `FILE`, use that as `'{"idx" :179, "svalue" : "$(< ${FILE} )" }'` – Inian Aug 28 '17 at 07:06
  • #!/bin/bash FILE="/home/pi/testar.log" '{"idx" :179, "svalue" : "$(< ${FILE} )" }' @powermeter:~ $ mosquitto_pub -h 192.168.0.117 -t domoticz/in -m "$(sudo /home/pi/a.sh)" /home/pi/a.sh: line 3: {"idx" :179, "svalue" : "$(< ${FILE} )" }: command not found – Micke Hedqvist Aug 28 '17 at 07:10
  • Which shell are you using `bash` or `sh`? – Inian Aug 28 '17 at 07:11
  • Just type this in terminal mosquitto_pub -h 192.168.0.117 -t domoticz/in -m "$(sudo /home/pi/a.sh)" – Micke Hedqvist Aug 28 '17 at 07:13
  • if you are in `sh`, you cannot slurp the file using the `<` operator, in which you need to use `cat`, as `'{"idx" :179, "svalue" : "$(cat FILE)" }'` – Inian Aug 28 '17 at 07:13
  • `#!/bin/bash FILE="/home/pi/testar.log" echo '{"idx" :179, "svalue" : "$(cat FILE)" }'` get this on logfile `2017-08-28 09:32:04.539 MQTT: Topic: domoticz/in, Message: {"idx" :179, "svalue" : "$(cat FILE)" }` – Micke Hedqvist Aug 28 '17 at 07:33
  • It is not clear what you are trying to suggest, did it work or not? if not add more details to the question – Inian Aug 28 '17 at 07:34

1 Answers1

0

the problem is the case.

An if you want the content of file, use "$(< ${file} )

thelastworm
  • 544
  • 4
  • 14