Need help on a script that sends an email message on disk usage

Hello All

I am new to scripting and need help on writing a script that sends an email message on disk usage, can some help me to understand the basics and how to write this.

Please help me.

Create a script sends an email message to the user specified on the command line if any of the filesystems at more than 70% of capacity. The script should not process special filesystems as /proc. It should only process filesystems which are either locally mounted or are mounted via NFS.

An individual email should be sent for each filesystem which is at the warning level. There should be a subject on the email with a message "Warning: Filesystem <put filesystem the>here is at <X>% of capacity" If the filesystem is at greater than 90% of capacity, the "Warning" should be changed to "Critical Warning".

You may use any scripting language including /bin/sh, ksh, bash, awk or perl. Work done in the C-Shell (csh) will not be accepted.
Who is Participating?
1badabingConnect With a Mentor Author Commented:
Hello All

I redid the script and to monitor and send a mail message, if less that 34 %. I keep getting an error for line 5.. see below..

df -k | grep -v 'proc' | awk '{ print $5 " " $1 }' | while read output;
  echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge 34 ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep%"

 $ ./
./ syntax error at line 5: `usep=$' unexpected
käµfm³d 👽Commented:
And how much effort have you put towards researching this homework assignment? Show us what you've done thus far, and ask specific questions about what you don't understand.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

1badabingAuthor Commented:
sorry for the delay, but i'm working on it  to get post for review
mokatellConnect With a Mentor Commented:
i have attached the needed files along with following example

you use this for gmail smtp settings  :


$name = "XXXXXXXX";
$nameMail ="XXXXXXXX";

$mailer = new PHPMailer();

$mailer->Mailer = 'smtp';
$mailer->Port = 465;
$mailer->SMTPDebug = 2 ;
$mailer->SMTPAuth = true;
$mailer->SMTPKeepAlive = true;
$mailer->Host = '';

$mailer->Username = 'XXXXXXXX';  // Change this to your gmail adress
$mailer->Password = 'XXXXXXXX';  // Change this to your gmail password
$mailer->From = $nameMail;  // This HAVE TO be your gmail adress
$mailer->FromName = $name; // This is the from name in the email, you can put anything you like here
$mailer->Body = XXXXXXXX;
$mailer->Subject = "XXXXXXXX";
1badabingAuthor Commented:
I am still working on getting my script to be posted
1badabingAuthor Commented:
This is what I came up with, not sure how to eliminate the /proc (which I need to) and whether I will get to email to the destination. Someone please help me

df -k | grep -v '^Filesystem | none' | awk '{ print $1 " " $5 }' | while read $output
 echo $output
 perc=$(echo $output | awk '{ print $2 }' | cut -d'%' –f2 )
 part=$(echo $output | awk '{ print $1 }' )

 if [ $perc -ge 90 ]; then
 echo "Critical Warning: Filesystem \"$part\" at “$perc”% of capacity” | \
 mail -s "Critical Warning: Filesystem \”$part\” at “$perc”% of capacity”

 elif [ $perc -ge 70 ] && [ $perc -lt 90 ]; then
 echo "Warning: Filesystem \"$part\" at “$perc”% of capacity” | \
 mail -s "Warning: Filesystem \”$part\” at “$perc”% of capacity”

1badabingAuthor Commented:
please close
1badabingAuthor Commented:
nothiong yet
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.