我正在使用gphoto2监控相机生成的事件。
示例输出是:
UNKNOWN PTP Event 400c, Param1 00010001
UNKNOWN PTP Event 400c, Param1 00010001
UNKNOWN PTP Event 400c, Param1 00010001
UNKNOWN PTP Event 2919, Param1 00000000
UNKNOWN PTP Event 400c, Param1 00010001
UNKNOWN PTP Event 400c, Param1 00010001
UNKNOWN PTP Event 2919, Param1 00000000
UNKNOWN PTP Event 400c, Param1 00010001
当拍摄新照片时出现“事件400c”(现在从试验中得知错误),我想在输出中找到这样的字符串时运行脚本(下载图像文件并继续我的过程)让显示器运行以备未来事件使用。
由于
答案 0 :(得分:2)
tail -f data_file | while read l
do
if [[ "$l" == *"Event 400c"* ]]
then
echo do something;
fi
done
当然,您需要用命令
替换echo命令答案 1 :(得分:0)
将其传递给grep,然后将输入字符串传递给脚本
输入流:
$ cat temp
UNKNOWN PTP Event 400c, Param1 00010001
UNKNOWN PTP Event 2919, Param1 00000000
UNKNOWN PTP Event 400c, Param1 00010001
UNKNOWN PTP Event 400c, Param1 00010001
UNKNOWN PTP Event 2919, Param1 00000000
UNKNOWN PTP Event 400c, Param1 00010001
处理数据的一些脚本:
$ cat temp.py
#! /usr/bin/python
import sys
for line in sys.stdin:
print "Input matching:", line,
管道:
$ tail -f temp | grep 400c | python temp.py
Input matching: UNKNOWN PTP Event 400c, Param1 00010001
Input matching: UNKNOWN PTP Event 400c, Param1 00010001
Input matching: UNKNOWN PTP Event 400c, Param1 00010001
Input matching: UNKNOWN PTP Event 400c, Param1 00010001