I'm trying to use the output of a bash command as an input variable for a sql-query:
#!/bin/bash
mysql --user=root --password=root database << QUERY_INPUT
#Get temp from sensor.
current_temp=$(sed -n 2,2p /sys/bus/w1/devices/xxx/w1_slave | awk '{print $10}' | awk -F= '{print $2}')
#SQL query
INSERT INTO temperatures (tdate, ttime, temperature)
VALUES (CURRENT_DATE,CURRENT_TIMESTAMP,'$current_temp')
QUERY_INPUT
Im getting:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'current_temp=24750
INSERT INTO temperatures (tdate, ttime, temperature)
VALUES' at line 1"
How can I pass only the numbers to the query?
/sys/bus/w1/devices/xxx/w1_slave? That line looks like it could be simplified greatly