我的 bash 脚本中出现意外的文件结尾

我的 bash 脚本中出现意外的文件结尾

我有一个脚本

#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

搜索后,似乎我所有的 if / fi 标签都已关闭,并且我在搜索时没有看到任何特殊字符:set lists。我是否缺少一些明显的东西?这似乎是造成这种情况的两个最大原因

谢谢

答案1

这是while循环。

您错过了几个关键字。语法必须是:

while <condition>; do <work>; done 

你的while循环从 开始while read output;,然后就没有了do .... done。使其为:

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

相关内容