我遇到了问题,我需要将尾部输出保存到mysql。我可以将输出保存到文件中,这是尾部命令:
tail -f file_ | egrep --line-buffered param_ > path_destinty
对于我的应用程序,有必要在写入信息时保存信息。
有什么提示吗?
示例:
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
管道:
- 尾部文件
- 因为 egrep 已被弃用,所以使用 grep -E
- 循环解析数据并将其发送到 MySQL
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