Question

I have a question about redirection linux command output (tshark) directly to MySQL database.

Tshark output looks like:

item-1:item-2:item-3:...:item-8

Is there any quite simple and beautiful way to redirect this output directly to MYSQL table with the rows "item-1"..."item-N"?

Any samples would be very useful for me :)

Was it helpful?

Solution

tshark-command|awk 'BEGIN {FS=":"};{print "insert into tbl_name (field1, field2, ..., field8) values (" $1 "," $2 "," $3 "," $4 "," $5 "," $6 "," $7 "," $8 ");"}' > insertcmd.sql

alternatively:

tshark-command|sed 's/^/insert into tbl_name \(field1,field2,...,field8\) values \(/g'|sed 's/:/,/g'|sed 's/$/);"

and finally:

mysql dbname < insertcmd.sql

I have not tested this, but it should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top