Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i got a file unexpected (expecting fi) but there is a fi in the following code #

ID: 3847590 • Letter: I

Question

i got a file unexpected (expecting fi) but there is a fi in the following code

#!/bin/sh

# picking the email

EMAILADD="test@test.com"

# settign warning to 50

WARNING=50

# Seteando a que critrico es a 90

CRITICAL=80

# ggenerate filesystem and place en $resultado

df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read resultado;

do

# echo $resultado

# obtain percentage from table

usep=$(echo $resultado | awk '{ print $1}' | cut -d'%' -f1 )

# analyze partition

partition=$(echo $resultado | awk '{ print $2 }' )

# check if critrical

if [ $usep -ge $CRITICO ]; then

echo "Critrical Low Space "$partition ($usep%)" on $(hostname) as on $(date)" |

mail -s "Critical Warning: $partition is at $usep% of capacity" $ELEMAIL;

elif [ $usep -ge $WARNING ]; then

echo "Warning Low Space "$partition ($usep%)" on $(hostname) as on $(date)" |

mail -s "Warning: $partition is at $usep% of capacity" $ELEMAIL;

fi

done

Explanation / Answer

The script works if you put single space after fi. See below:

#!/bin/sh
# picking the email
EMAILADD="test@test.com"

# settign warning to 50
WARNING=50

# Seteando a que critrico es a 90
CRITICAL=80

# ggenerate filesystem and place en $resultado
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read resultado;
do
# echo $resultado
# obtain percentage from table
usep=$(echo $resultado | awk '{ print $1}' | cut -d'%' -f1 )
# analyze partition
partition=$(echo $resultado | awk '{ print $2 }' )
# check if critrical
if [ $usep -ge $CRITICAL ]; then
echo "Critrical Low Space "$partition ($usep%)" on $(hostname) as on $(date)" |
mail -s "Critical Warning: $partition is at $usep% of capacity" $ELEMAIL;
elif [ $usep -ge $WARNING ]; then
echo "Warning Low Space "$partition ($usep%)" on $(hostname) as on $(date)" |
mail -s "Warning: $partition is at $usep% of capacity" $ELEMAIL;
fi
done