I check conditional check logs and copy to another folder. The while loop executes for the first iteration. At the next iteration, the copy of the file does not work. here is my code.
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
tail -n 0 -F hive-server2.log | \
while read LINE
do
if [ `echo "$LINE" | grep -c "DROP" ` -gt 0 ]
then
AuditTypeID=14
QueryResult="$(grep -oEi 'DROP TABLE [a-zA-Z][a-zA-Z0-9_]*' hive-server2.log | sed -n \$p)"
echo -e "$QueryResult" >/dev/null < op.txt
cp op.txt op/op.txt.$current_time
fi
done
In the first iteration, the output file is created and stored in the op directory. In the next iteration, the file is not created.
Expected result: for each iteration, a new file should be created in the op directory.
Any help would be appreciated.
source
share