Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"];
    then
    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
  else
   echo "Taking Backups"
    cd $mixB
#    tar command
    cd $profiles
#    mysqldump command

echo "Doing a git pull"
#    git stuff   

    echo "Finishing touches"
#    stuff
  fi

  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 ]
      then
      echo "Error $res on $1"
      exit 1
    fi
  }
  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

Thanks

share|improve this question

closed as off-topic by jasonwryan, dhag, cuonglm, Archemar, slm Dec 12 '15 at 14:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – jasonwryan, dhag, cuonglm, Archemar, slm
If this question can be reworded to fit the rules in the help center, please edit the question.

    
unrelated to your actual problem, but one of your test commands is missing the spaces around the brackets: ["$partition" == "/tmp"], and I don't think == is valid, anyway. – drewbenn Dec 11 '15 at 18:03
    
Oh, is it just = then? I wasn't completely sure. – user1210304 Dec 11 '15 at 21:12
    
Actually I think it should work. It wasn't listed in help test, but man bash does say the = operator is equivalent to ==. so you're okay. – drewbenn Dec 11 '15 at 21:21
    
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
up vote 4 down vote accepted

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
done
share|improve this answer

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