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
\
. (1c) And, when you post code, please indent it correctly. … (Cont’d) – Scott - Слава Україні Dec 12 '15 at 00: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 00:24cd "$mixB"
,curl -s -I "$1"
, andif [ "$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, thefunction
keyword is non-standard.test_web() {
…
}
is more portable. (8)awk {'print $2'}
might work, but it’s conventional to sayawk '{print $2}'
. – Scott - Слава Україні Dec 12 '15 at 00:25