I’m trying hard to write a script function that reads the last line of a log file while that file is being updated, to use it in arguments.
My idea is to stop the loop when a file is created by another function of the same script. That seems to work. However, after spending hours, I have not been able to actually get the data from the log file.
Got these two versions now;
while true; do
if [[ -f "CheckFile" ]]; then
break
else
Variable=$(tail -n 1 "${LogFile}" | grep -E "(Installing.* of .*)")
echo "${Variable}"
fi
done
rm -f "CheckFile"
while true; do
if [[ -f "CheckFile" ]]; then
break
else
while read line; do
if [[ -n $line ]]; then
echo "test $line"
else
continue
fi
done < <(tail -n 1 "${LogFile}" | grep -E "(Installing.* of .*)")
fi
done
rm -f "CheckFile"
I expected both versions will give an updated value as long as the while loop runs. Also tried with tail -f, but that seems to never end.