Solved

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

Posted on 2013-01-31
9
499 Views
Last Modified: 2013-03-25
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.


Requirements;
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.
0
Comment
Question by:1badabing
9 Comments
 
LVL 10

Assisted Solution

by:deviprasadg
deviprasadg earned 250 total points
ID: 38842681
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38843608
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.
0
 

Author Comment

by:1badabing
ID: 38846164
sorry for the delay, but i'm working on it  to get post for review
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Assisted Solution

by:mokatell
mokatell earned 250 total points
ID: 38850008
i have attached the needed files along with following example

you use this for gmail smtp settings  :


<?php
require("class.phpmailer.php");

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


$mailer = new PHPMailer();


$mailer->Mailer = 'smtp';
$mailer->IsSMTP();
$mailer->IsHTML(true);
$mailer->Port = 465;
$mailer->SMTPDebug = 2 ;
$mailer->SMTPSecure='ssl';
$mailer->SMTPAuth = true;
$mailer->SMTPKeepAlive = true;
$mailer->Host = 'smtp.gmail.com';

$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";
$mailer->AddAddress($address);
$mailer->Send();
?>
class.phpmailer.php
class.pop3.php
class.smtp.php
0
 

Author Comment

by:1badabing
ID: 38903471
I am still working on getting my script to be posted
0
 

Author Comment

by:1badabing
ID: 39006230
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


#!/bin/bash
df -k | grep -v '^Filesystem | none' | awk '{ print $1 " " $5 }' | while read $output
do
 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” 1badabing@expert.com

 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” 1badabing@expert.com

 fi
done
0
 

Accepted Solution

by:
1badabing earned 0 total points
ID: 39006266
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..


*********************************************************
 more filecheck.sh
#!/bin/sh
df -k | grep -v 'proc' | 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 34 ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep%" pulorie1@yahoo.com
  fi
done

*********************************************************
 $ ./filecheck.sh
./filecheck.sh: syntax error at line 5: `usep=$' unexpected
0
 

Author Comment

by:1badabing
ID: 39009485
please close
0
 

Author Closing Comment

by:1badabing
ID: 39017243
nothiong yet
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Regular expressions Exclude patter 3 35
Using a variable to name output in powershell script 2 36
Configure Robocopy to excluding folders 6 55
How can i open a .fxp file 3 29
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now