title: Bash script error. Syntax error near unexpected token
body: <p>I'm trying to work through a script to email me a notification if the load is too high on our server. I found a good one but it's giving me and error when I run it, and I can't see why.</p>
  
  <p>Running the code below gives the error:</p>
  
  <blockquote>
    <p>line 13: syntax error near unexpected token `fi'</p>
  </blockquote>
  
  <p>I thought I had to laid out correctly though. Thanks!</p>
  
  <pre><code>#!/bin/bash
  
  THR=10
  MAIL="address@domain.com"
  
  VAR=`uptime|awk -F, '{print $4}'|awk '{print $3}'`
  OUT=`echo "$VAR $THR" | awk '{if ($1 &gt; $2) print "yes"; else print "no"}'`
  if [ "$VAR" == "" ]
  then
    # it's within the first 24 hours of uptime
    VAR=`uptime|awk -F, '{print $3}'|awk '{print $3}'`
    OUT=`echo "$VAR $THR" | awk '{if ($1 &gt; $2) print "yes"; else print "no"}'`
  fi
  if [ "$OUT" == "yes" ]
  then
    echo "The current load $VAR is greater than the threshold $THR" | mail $MAIL
    -s "Server Load Alert"
    echo "Alert generated because $VAR is greater than $THR"
  else
    echo "No alert as $VAR &gt; $THR"
  fi
  echo "load = $VAR"
  </code></pre>