I have a "for" loop which passes the results to a file called "results" Occasionally an error stream is detected and the loop continues trying within the loop for a number of times before it exits and moves onto the next iteration. I'd like to detect an error result when it first occures and move onto the next iteration. I've had three attempts to do this - none of which have worked.
edit:- To put it in context this code preceding;
wl_pass=input.txt
for fn in `cat $wl_pass`; do
wpscan --url $fn -e u vp vt >> "results"
Attempt 1
if [ "tail -1 -f results" == "Error" ];
then
echo "error detected"
continue
fi
Attempt 2
while [ $("tail -1 -f results" | grep -o0 -c "Error") -eq 0 ]; do continue; done
Attempt 3
tail -f "results" | grep --line-buffered "Error" | while read line ; do
continue
done
Any advice would be welcome
Thanks for the input -->> this is what I have so far. I'm still having problems with it:-
wl_pass=input.txt
wl_pass="${wl_pass}"
count_pass=$(wc -l $wl_pass | cut -d " " -f1)
while true
do
timestamp=`date +%s`
echo start $timestamp >> results
for fn in `cat $wl_pass`
do
wpscan --url $fn -e u vp vt >> results
echo end $timestamp >> results
if sed -n '/start $timestamp/,/end $timestamp/p' results | grep -E 'Error:'; then
break
# continue
fi
done
done
tailhere? Is your log file millions of lines? Wouldn't it simpler to justgrepthe whole thing?results. What should happen whenErroris found or otherwise? Do you want to change the behavior of theforloop or the processing of the output?