将尾输出保存到mysql

时间:2013-10-31 13:24:26

标签: mysql database linux save tail

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

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

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

任何提示?

1 个答案:

答案 0 :(得分: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
  4. 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
    
相关问题