【问题标题】:Save tail output to mysql将尾部输出保存到 mysql
【发布时间】:2013-10-31 13:24:25
【问题描述】:

我有一个问题,我需要将尾部输出保存到 mysql。我可以将输出保存到文件中, 这是tail命令:

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

对于我的应用程序,有必要在编写时保存信息。

有什么建议吗?

【问题讨论】:

  • 但是您遇到了什么问题?这行不通吗?
  • 这行得通,但我需要保存到 mysql 的文件中。

标签: mysql database linux save tail


【解决方案1】:

例子:

 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

管道:

  1. 跟踪您的文件
  2. 因为不推荐使用 egrep,所以使用 grep -E
  3. 解析数据并将其发送到 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

【讨论】:

  • 感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-12
  • 2020-12-29
  • 2016-02-28
相关资源
最近更新 更多