For example, CPU temperature is added to the DB regularly using Linux commands. At this time, I searched variously with just the command to try to reduce the code as much as possible, but I created it because it was quite difficult.
I want to make it usable for general purposes, so I want to realize a movement like Format of python.
Now this.
import sys;
print(sys.argv[1].format(*sys.argv[2].split(" ")) )
mosquitto_sub -t "#" -v |xargs -I@ python3 /home/hashito/command/text2format.py "insert into mqtt.msg (t,m,tm)values(\'{}\',\'{}\',UNIX_TIMESTAMP(NOW()))" @ | xargs -I@ mysql -e "@"
I will put the contents of mqtt into Maria DB
We received a comment from @shiracamus. It seems that you can do it in the following form with only commands.
$ echo "a b" | xargs echo | xargs printf "insert into mqtt.msg (t,m,tm)values('%s','%s',UNIX_TIMESTAMP(NOW()))"
insert into mqtt.msg (t,m,tm)values('a','b',UNIX_TIMESTAMP(NOW()))
I've been looking for this for a long time, but I was saved because I didn't have my own knowledge! Thank you very much!
Recommended Posts