mysql - How do you update/add to SQL tables with bash commands? -


need add snmp information sql database , update on regular schedule. snmp info can queried bash commands.

you can use bash commands write insert statements file, pipe file mysql program.

say have file looks this:

key1,1.0 key2,1.4 key3,1.9 key4,2.0 key5,3.5 

you can pipe bash script looks like:

#!/bin/bash  while read key, value;     echo "insert sometable(key, value) values('$key' $value);" done >/tmp/inserts.sql  mysql </tmp/inserts.sql >/tmp/inserts.out 

if data comes somewhere else same principle, generate sql commands file , pipe them mysql.

this strategy isn't kludgy might seem @ first. mysql's own mysqldump backup utility dumps database file in form of sql statements.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -