while loop output

:wall:Hi
I am a beginner to unix

In a shell script i see the below code

# set admin email so that you can get email
ADMIN=someone@somewhere.com
host=`hostname`
date=`date`
# set alert level 70% is default
ALERT=70
df -h | grep / | grep -v '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  echo $output;
  usep=`(echo $output | awk '{ print $1}' | cut -d'%' -f1  )`
  partition=`(echo $output | awk '{ print $2 }' )`
  if [ $usep -ge $ALERT ]; then
    echo "Running out of space \"$partition ($usep%)\" on "$host" as on "$date |
     mailx -s "Alert: Almost out of disk space $usep" $ADMIN
  fi
done

As we can see the script is send an alert email to the user when disk space exceeds 70%.
what I could not under stand is below line

df -h | grep / | grep -v '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;

we are diverting the modified df -h output to "while loop output". what does this mean?
how many times the loop is executed?

please provide any guidance.

thanks
p.

it is going to read line-by-line the modified output of "df". Each line is read into variable "output" so that you can process them. Therefore it'll be executed for each line of output.

I'm not sure the usefulness of grep / , as I imagine every mount-point starts with / anyway. I see much room for improvement in this code. probably you'd want grep -Ev '^Filesystem|tmpfs|cdrom' . you can simplify so much into the awk process.. since you're not doing anything for entries under the alert level, you can let awk filter that out. read can also split the lines into variables, so you won't have to do echo $output | awk ...

$ df -h | awk -v "alert=70" '$1 !~ /cdrom|tmpfs/ && 0+$5>alert {print $5, $1 }' |
> while read usep partition; do echo "$partition is $usep full"; done

/dev/xvda2 is 99% full