I'm having a problem, I need to save the tail output to mysql. I can save the output to a file, Here is the tail command:

tail -f file_ | egrep --line-buffered param_ > path_destinty

For my application it is necessary to save the information in the time that it is written.

Any tips?

有帮助吗?

解决方案

Example:

 tail -f file_ | \
 grep -E --line-buffered param_ | \
 while read line; do \
 mysql -E -u root -p root -h 127.0.0.1 'INSERT INTO `test`.`test` (`text`, `updated`) VALUES ("'${line}'", NOW());'; done

Pipes:

  1. tail your file
  2. because egrep is deprecated, use grep -E
  3. cycle for parsing data and send them to MySQL

Params of MySQL:

-E       Execute query
-u       Username
-p       Password for this user
-h       Host/IP
`test`   is the name of the database and table
${line}  our varible with text
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top