所以我运行以下的shellcript,并在意外令牌'done'附近收到错误语法错误。这有什么问题?我错过了什么?
#!/bin/sh
df -H | grep -vE '^Filesystem|tmpf|cdrom' | awk ' {print $5 " " $6}' | while read output
do
echo $output
usep=$(echo $output | awk '{print $1}' | cut -d'%' -f1)
echo $usep
partition=$(echo $output | awk '{print $2}' )
if [ $usep -ge 90 ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date) : $usep%" |
mail -s "Alert: Critical Almost out of disk space $partition $usep%"
user@mail.eu
fi
if [ $usep -ge 5 ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date) : $usep%" |
mail -s "Alert: Warning Almost out of disk space $partition $usep%" user@mail.eu
fi
done
答案 0 :(得分:1)
我复制粘贴你的脚本并在Cygwin下进行测试。
我使用Windows end-of-line(CRLF)获取语法错误但是如果转换为Unix EOL(LF),脚本可以正常工作