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?

3
  • 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?? Commented Dec 2, 2016 at 9: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. Commented Dec 2, 2016 at 9:40
  • 1
    Maybe these links may be useful: why-is-using-a-shell-loop-to-process-text-considered-bad-practice and why-is-looping-over-finds-output-bad-practice Commented Dec 2, 2016 at 9:52

1 Answer 1

-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
2
  • Still the same error Commented Dec 7, 2016 at 8:24
  • if you run with bash -x script.sh what is the output.. where it shows the error ? what is your OS Commented Dec 7, 2016 at 10:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.