Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
It appears to be exactly what I'm looking for, but it fails with "./slew.sh: line 33: syntax error: unexpected end of file". I'm running the script by doing "./shew.sh 90".
Can anyone shed some light on this?
Code:
#! /bin/bash
## SLEW: Space Low Early Warning
## by James T. Dennis,
## Starshine Technical Services
##
## Warns if any filesystem in df's output
## is over a certain percentage full --
## mails a short report -- listing just
## "full" filesystem.
## Additions can be made to specify
## *which* host is affected for
## admins that manage multiple hosts
adminmail="root"
## who to mail the report to
threshold=${1:?"Specify a numeric argument"}
## a percentage -- *just the digits*
# first catch the output in a variable
fsstat=`/bin/df`
echo "$fsstat" \
| gawk '$5 + 0 > '$threshold' {exit 1}' \
|| echo "$fsstat" \
| { echo -e "\n\n\t Warning: some of your" \
"filesystems are almost full \n\n" ;
gawk '$5 + 0 > '${threshold}' + 0 { print $NF, $5, $4 }' } \
| /bin/mail -s "SLEW Alert" $adminmail
exit
I took another look at the script and found out that the part between the curly braces are the problem (and not the OR part as mentioned earlier). The problem is that I cannot get the script to work the way the author intended it to work......
I do have an alternative based on what the above script does:
Code:
#!/bin/bash
# who to mail the report to
adminMail="root"
# a percentage -- *just the digits*
threshold=${1:?"Specify a numeric argument"}
# store output
output=$(/bin/df | \
gawk -v threshold=$threshold '
$5 + 0 >= threshold { print $NF, $5, $4 }
')
# if output is filled, it needs to be reported/mailed
if [[ -n $output ]]
then
/usr/bin/mail -s "Filesystem Alert" $adminMail << TOEND
"Warning: some of your filesystems are almost full:"
$output
TOEND
fi
exit 0
You need to check if the mail program resides in /bin or /usr/bin and change that line in the script accordingly.
Thank you very much for the replies! And a very big thank you for taking the time to write the script!
Unfortunately, though... I run the script and just get dropped back to a prompt. I have 8 filesystems which should be reported as over the 90% threshold, but there is nothing output to the terminal or console, and nothing to root's mail.
I did have to change the entry for the mail program to "/bin/mail", as you anticipated.
Many thanks for your help with this. Our web server at work was set up badly by a third party, and I would like to be alerted before the impending problem of the server filling (they have everything under the / filesystem!)
Strange it doesn't work, I did test it on my side and it worked fine.
Ok, what happens if you replace this:
/usr/bin/mail -s "Filesystem Alert" $adminMail << TOEND
"Warning: some of your filesystems are almost full:"
$output
TOEND
To:
echo $output
If that doesn't show anything, you can safely assume that it is not a mail problem. If it does give some output, the mail part is the problem.
Another thing, I assume that all output of the df command is the same, but just to be sure this is what I get when running df (just a few relevant lines):
Code:
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 66055932 14327388 48373104 23% /
/dev/sda4 364794160 100748640 245515012 30% /data
/dev/sdb3 11820088 160524 11059136 2% /tmp
The bold parts (field 5) is what we are interested in.
Ah, that did give the output I need. Looks like a mail problem then! Although I'm testing this on my home PC, not the server at work. I'm happy that mail is working fine on the server, as I've set it to e-mail me the backup reports each morning which works fine.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.