I have a script

#Check the disk space before backups are taken
echo "Checking Disk Space"
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;

echo $output
space=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
partition=$(echo $output | awk '{ print $2 }' )
  if [ $space -ge 90 ] && ["$partition" == "/tmp"];
    echo "Running out of space \"$partition ($space%)\" on ($hostname) as of "`date +%D-%l`")" | mail -s "Alert: Almost out of disk space $space%"
    exit 1
   echo "Taking Backups"
    cd $mixB
#    tar command
    cd $profiles
#    mysqldump command

echo "Doing a git pull"
#    git stuff   

    echo "Finishing touches"
#    stuff

  echo "Checking if the website is up"
  function test {
  res=`curl -s -I $1 | grep HTTP/1.1 | awk {'print $2'}`
    if [ $res -ne 200 ]
      echo "Error $res on $1"
      exit 1
  test http://www.google.com

After searching, it appears all of my if / fi tags are closed, and I didnt see any special characters when I did :set lists. Is there something obvious that I am missing? Those seem to be the two biggest causes of this e


  • Oh, is it just = then? I wasn't completely sure. Dec 11 '15 at 21:12
  • Argghhh!  (1) Debugging 101: delete code until the problem goes away; then the last thing you deleted is the cause of the error.  If you reach a point where you can’t delete any more (as might happen in your case), take a good, long, hard look at what’s left.  If you still can’t solve it, post that.  (1b) If the code you post has scroll bars, it’s still too long.  If you really really really need to have a command line that’s more than 80 characters long, break it into shorter lines with \.  (1c) And, when you post code, please indent it correctly.  … (Cont’d)
    – Scott
    Dec 12 '15 at 0:21
  • (Cont’d) …  (2) Rather than read output, why not do read space partition?  OK, yes, you still need to strip off the %, but it’s simpler than what you’re doing.  (3) You don’t need to break out of quotes to use `…`, so instead of "Running out of space … as of "`date +%D-%l`")", you can say "Running out of space … as of `date +%D-%l`)".  In fact, it’s safer to leave it inside the quotes.  (4) For clarity, you might want to change `…` to $(…) — see this, this,  … (Cont’d)
    – Scott
    Dec 12 '15 at 0:24
  • (Cont’d) …  and this. (5) You should always quote shell variables (e.g., cd "$mixB", curl -s -I "$1", and if [ "$res" -ne 200 ]) unless you have a good reason not to, and you’re sure you know what you’re doing.  (6) “test” is the name of a shell built-in command.  Defining a function by the same name is confusing and may cause problems eventually.  (7) Also, the function keyword is non-standard.  test_web() { } is more portable.  (8) awk {'print $2'} might work, but it’s conventional to say awk '{print $2}'.
    – Scott
    Dec 12 '15 at 0:25

It's the while loop.

You have missed couple of keywords. The syntax needs to be:

while <condition>; do <work>; done 

Your while loop starts with while read output;, then there is no do .... done. Make it as:

awk .... | while read output; do
    #### Do what you want

Not the answer you're looking for? Browse other questions tagged or ask your own question.