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

I got the following code but i need to exlude systems folders such as proc ufs e

ID: 3848789 • Letter: I

Question

I got the following code but i need to exlude systems folders such as proc ufs ext2 and ext4 how do i do this

#!/bin/sh
# Set to email address to send to
EMAILADDR="carlos_lopezmelero@student.uml.edu"

# Set warning percentage
ALERT=70

# Set critical warning percentage
CRITALERT=90

# Get the listing of filesystems and put in $output
df -h | grep -vw '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
echo $output
# Grab just the percentage
usep='echo $output | awk '{ printf $1 }' | cut -d '%' -f1 '
# Grab the partition
partition='echo $output | awk '{ printf $2 }' '
# First check for critical since it's higher value
if [ "$usep" -ge "$CRITALERT" ]; then
# echo the body to the mail program (-s is subject) and send
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)" |
mail -s "Critical Warning: Warning: $partition is at $usep% of capacity" $EMAILADDR
# If it's not above critical, test to see if it's above alert
elif [ "$usep" -ge "$ALERT" ]; then
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)" |
mail -s "Warning: $partition is at $usep% of capacity" $EMAILADDR
fi
done

Explanation / Answer

Explanation:

As per my understanding from the code shared if you want to avoid certain folders. This is how you should proceed.

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

you have to change the above grep command to avoid the folder you dont want to be included. Also the above grep command should throw an error because you are not using -E option for extended grep. The best way is to use egrep command like below which generally unix programmers use while grepping for multiple patterns.

df -h | egrep -vw '^Filesystem|tmpfs|cdrom|proc|ufs|ext2|ext4' | awk '{ print $5 " " $6 }' | while read output;

If you want to make the egrep insensitive then you can use -i option along with -vw.

NOTE: Let me know if this is not what you expect. Also clearly point out what you are needed so i can clarify.