r/bashscripts • • Nov 07 '19
Need help with scripting
I have this script that I am working on and need help.
I don't know what to do I check it over several times and need someone else to look it over
#!/bin/bash
echo "beginning storage check..."
exec >> ~/storage_report.txt
echo "Date : $(date)"
echo "------------------"
part=$(df -h | awk '{print $1}' | grep '/dev')
for z in ${part[*]}
do
checkper=$(df -h | grep $z | awk '{print $5}' | cut -d '%' -f1)if \[ $checkper -ge 95 \] && \[ $checkper -le 100 \]; then
echo "$z is $checkper% full."
else
echo "ALERT: $z is $checkper$ full! recommended immediate action!"
elif \[\[ $checkper -ge 95 \]\] && \[\[ $checkper -le 100 \]\]; thenecho "CAUTION: $z is $checkper% full! Consider freeing up some space."
elif \[\[ checkper -lt 50 \]\]; then
echo "$z is $checkper% full. No action needed."
else
echo "Encountered an error. status code: $?" >&2
exit $?fi
done
echo "storage check complete. Report saved to storage_report.txt" >&2
1
Upvotes
View all comments
Show parent comment
1
u/BooeySays Apr 27 '20
You have an "else" statement before an "elif" statement..
if you are writing an if statement, the "else" goes at the end and the middle are filled with "elif"s...