sql - Bash script to insert values in MySQL -


i want make bash script connects mysql server , inserts valuse txt file. have written down:

#!/bin/bash echo "insert test (ip,mac,server) values ('cat test.txt');" | mysql -uroot -ptest test; 

but i'm recieving following error:

error 1136 (21s01) @ line 1: column count doesn't match value count @ row 1

i suppose error in txt file, i've tried many variations , still no hope of success.

my txt file looks this:

10.16.54.29 00:f8:e5:33:22:3f marsara

try one:

#!/bin/bash inputfile="test.txt" cat $inputfile | while read ip mac server;     echo "insert test (ip,mac,server) values ('$ip', '$mac', '$server');" done | mysql -uroot -ptest test; 

this way streaming file read mysql comand execution.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -