0

I need to record temperatures to a SQLite-DB on a linux system (using bash)

My problem is that I get the temperature readings in an individual file. How can I get that reading into the SQLite command

 sqlite3 mydb "INSERT INTO readings (TStamp, reading) VALUES (datetime(), 'xxx');"

The file contains just one line with the value "45.7" and should replace the xxx. Using fix data the SQL command works pretty well.

2
  • Please add sample input file to your question. Commented Feb 21, 2016 at 16:52
  • You might be interested in the .import CLI command: sqlite.org/cli.html Commented Feb 21, 2016 at 19:42

1 Answer 1

1

You can simply echo commands to the sqlite3, just like this:

temp=`cat file_with_temperature_value`
echo "INSERT INTO readings (TStamp, reading) VALUES (datetime(), '$temp');" | sqlite3 mydb

or do it like in your example:

temp=`cat file_with_temperature_value`
sqlite3 mydb "INSERT INTO readings (TStamp, reading) VALUES (datetime(), '$temp');"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.