Skip to main content
5 of 7
added 137 characters in body
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

The reason you're getting a syntax error is that your else if statements should be elif.

If you give wc -l two files, it will produce three lines of output:

$ wc -l .profile .profile
      30 .profile
      30 .profile
      60 total

This affects the very first if test where $WCOUNT is unquoted, and its expansion introduces another syntax error.

You probably want

WCOUNT=$( wc -l <output.txt )

Additionally, you have a number of tests on strings like "grep DHCPSTART output.txt". These tests will always be true.

To test whether a string is present in a file, use

if grep -Fq 'fixed string' filename; then

e.g.

if grep -Fq 'CLIENTSTART' output.txt; then
   # do something
elif grep -Fq 'DHCPSTART' output.txt; then
   # do something
else
   # do something
fi

The -q stops grep from producing any actual output. Its exit status will tell whether the string was found or not and this is what makes the if statement work (the flag also makes grep stop reading the file at the first match). The -F flag makes grep treat the given pattern as a fixed string rather than as a regular expression.

Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k