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

Create a script that sends an email message to the user specified on the command

ID: 3670907 • Letter: C

Question

Create a script that sends an email message to the user specified on the command line if any of the file systems are at more than 60% of capacity. The script should not process special file systems as /proc. It should only process file systems which are either locally mounted or are mounted via NFS. An individual email should be sent for each file system which is at the warning level (60%) There should be a subject on the email with a message "Warning: File system here is at % of capacity". If the files system is at greater than 90% of capacity, the "Warning" should be changed to "Critical Warning".

Use any scripting language including /bin/sh, ksh, bash, awk or perl. Work done in the C-Shell (csh) will not be accepted. The same program must be able to be run on both Ubuntu and Solaris.

Explanation / Answer

Here you go :

#!/bin/bash
touch file
df -Ph | awk '{print $5}' > file

while read line; do
if [$line -gt 60]
then
msg="Critical Warning: File system here is at $line of capacity"
else
msg="Warning: File system here is at $line of capacity"
fi
echo $msg | mail -s "a subject" someone@somewhere.com
done < file

this is written in bash. its pretty straight forward. but I would suggest you should read awk for better understanding of this.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote