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
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:03help test
, butman bash
does saythe = operator is equivalent to ==.
so you're okay. – drewbenn Dec 11 '15 at 21:21\
. (1c) And, when you post code, please indent it correctly. … (Cont’d) – Scott Dec 12 '15 at 0:21read output
, why not doread 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