0
find . -name 'Email*.log' -exec grep -il 'bad password' {} \;| while read line; do
  TEMPNUM=`tail -20 $line | grep 'bad password' | wc -l`
  if [ $TEMPNUM -gt 0 ]; then
     awk '/Username/{print $NF}' $line >> expiredmailbox.txt
  fi
done

This is the code I used and ran the shell script. I am getting
line 6: syntax error near unexpected token `done' Even if just try to echo the $line. I am getting an error. How can I eliminate this?

Kamaraj
  • 4,295
  • 1
  • 12
  • 18
  • hmm the syntax looks ok - your script seems to work for me apart from the `awk` (works if I replace with `echo "$line"`) (you probably want to add a `-type f` to your `find` command to stop `grep` throwing errors and quote your `"$line"` variable but I don't think those things are your problem). Are you sure you copied your script here exactly?? – Zanna Dec 02 '16 at 09:28
  • In which shell you are working, is it perhaps `bash`? Assuming you need loops at all it would make things quite a bit easier. – phk Dec 02 '16 at 09:40
  • 1
    Maybe these links may be useful: [why-is-using-a-shell-loop-to-process-text-considered-bad-practice](http://unix.stackexchange.com/questions/169716/why-is-using-a-shell-loop-to-process-text-considered-bad-practice) and [why-is-looping-over-finds-output-bad-practice](http://unix.stackexchange.com/questions/321697/why-is-looping-over-finds-output-bad-practice) – andreatsh Dec 02 '16 at 09:52

1 Answers1

-1

can you try this..

#!/bin/bash

find . -name 'Email*.log' | xargs grep -li  'bad password' |  while read line
do
  TEMPNUM=$(tail -20 "${line}" | grep -c 'bad password')
  if [ "${TEMPNUM}" -gt "0" ]; then
     awk '/Username/{print $NF}' "${line}" >> expiredmailbox.txt
  fi
done
Kamaraj
  • 4,295
  • 1
  • 12
  • 18