Вопрос

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