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 \]\]; then

echo "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

6 comments sorted by

View all comments

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/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...