Использование Tee
и перенаправить его к Стдерру
my_command | tee /dev/stderr | grep -q '^Error'
, он сохранит GREP
состояние выхода и дублировать весь вывод на STDERR, который виден в консоли. Если вам это нужно в stdout, вы можете перенаправлять его там позже, как это:
( my_command | tee /dev/stderr | grep -q '^Error' ) 2>&1
Обратите внимание, что GREP
ничего не выводится, но он будет на Tee
.
Для закрытия, это начало скрипта, который я собираюсь использовать. Он нуждается в дополнительной работе, чтобы сделать его надежным и выполнять протоколирование, но вы должны получить общую идею.
#!/bin/sh
# This script should be executed from a crontab that executes every 5 or 10 minutes
# the find below looks for all log files that do NOT have the sticky bit set.
# You can see the sticky bit with a "T" from a "ls -l".
for x in `find /home/tomcat/openam/openam/log/ -name "log-*" -type f ! -perm -1000 -print`
do
# Look for open files. For safety, log that we are skipping them
if lsof | grep $x > /dev/null; then
# create a log entry on why I'm not processing this file...
echo $x " is open"
else
# $x "is closed and not sticky"
# run the awk scripts to process the file!
echo $x " processing with awk..."
# Set the sticky bit to indicate we have processed this file
chmod +t $x
fi
done
Попробуйте использовать уведомитьwait
для этого:
inotifywait -e close_write /home/tomcat/openam/openam/log/CURRENT_OPENED_LOG_FILE