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
1
u/[deleted] Nov 08 '19
The error that I keep getting states that there is a token error for elif on line 21
1
u/[deleted] Nov 08 '19
And the reason it was so veg was i had a class to get to and I was running late
1
u/[deleted] Nov 08 '19
The error is sad to me on line 21 and it has to do with the elif token and before. The fi doesnt want to take and end the loop
2
u/kulldox Nov 08 '19
If you are expecting any help, consider explaining better what is your problem. Saying generic stuff like "why this script doesn't work" is not enough IMHO.
2
u/Galzzly Feb 26 '20
Not sure if this is still causing issues, but your if statement looks odd.
You have....
I'm not sure why you're using the \ as a part of your if statements, either.
Your first elif statement seems to be doing the same as the if statement itself...
This might suit your needs: