我想在一个脚本中添加多个尾部脚本。
第一个:
tail -f /var/script/log/script-log.txt | if grep -q "Text1"; then echo "0:$?:AAC32 ONLINE"
fi我想再添加5行不同的单词,可以吗?
else if、if等
谢谢!
发布于 2017-09-25 20:36:59
tail -f /var/script/log/script-log.txt | if grep -E "Text1|Text2|Text3"; then echo "0:$?:AAC32 ONLINE" fi发布于 2017-09-25 20:43:34
在您的例子中,使用逻辑AND运算符就足够了:
tail -f /var/script/log/script-log.txt | grep -q "text1\|text2\|text3" && echo "0:$?:AAC32 ONLINE"发布于 2017-09-25 20:48:13
#!/bin/sh
PIPENAME="`mktemp -u "/tmp/something-XXXXXX"`"
mkfifo -m 600 "$PIPENAME"
tail -f /tmp/log.txt >"$PIPENAME" &
while read line < "$PIPENAME"
do
echo $line # Whatever you want goes here
done
rm -f "$PIPENAME"如果您需要特定于Bash,可以使用-u选项进行读取,然后可以在循环开始之前对命名管道执行rm操作,这样做可以确保在完成操作后保持干净。
https://stackoverflow.com/questions/46405243
复制相似问题