- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- FileSystemAlert Script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 05:39 AM
07-14-2003 05:39 AM
Kyle
------------------------------------------
#!/usr/bin/sh
#Script Name: FileSystemAlert
#Author: Cpl Harris
#Date: July 10, 2003
#Purpose: To send out an email alerting admin when a filesystem is over 97 %
mark=1
while [ $mark = 1 ]
do
df | grep -v Filesystem |
while read line
do
MTP=$(echo "$line" | awk '{print $6}')
USE=$(echo "$line" | awk '{print $5}' | sed 's/.$//g')
if [ "$USE" > "60" ]
then
echo "$MTP $USE " | mail -s "FS alert" harriskd@mcsc.usmc.mil
sleep 100 #or whatever time
else
sleep 100 #or whatever time
fi
done
done
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 05:57 AM
07-14-2003 05:57 AM
Re: FileSystemAlert Script
I think that /usr/bin/sh (first line) isn't the correct path for the shell interpreter. In my system (Redhat 73) I must use /bin/sh.
I made this correction and the script seems to work (I executed it manually, not by cron).
You can check the exact location of sh so:
$ which sh
hth
Claudio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:01 AM
07-14-2003 06:01 AM
Solutionmark=1
while [ $mark = 1 ]
do
df | grep -v Filesystem | while read line
do
MTP=$(echo "$line" | awk '{print $6}')
USE=$(echo "$line" | awk '{print $5}' | sed 's/.$//g')
if [ "$USE" -gt "30" ]
then
echo "$MTP $USE "
#echo "$MTP $USE " | mail -s "FS alert" harriskd@mcsc.usmc.mil
#sleep 100 #or whatever time
#else
#sleep 100 #or whatever time
fi
done
sleep 100
done
this script works.
1. use -gt for numeric comparisons. > for string comparisons.
2. dont put the sleep in if /else loops. for every line of ur df outptut the script will sleep. instead have it in the outer loop.
cheers
-balaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:06 AM
07-14-2003 06:06 AM
Re: FileSystemAlert Script
try this:
----------------------------------------------
#! /bin/sh
df | grep -v Filesystem |
while read line
do
MTP=$(echo "$line" | awk '{print $6}')
USE=$(echo "$line" | awk '{print $5}' | sed 's/.$//g')
if [ "$USE" -gt "60" ]
then
echo "$MTP $USE "
fi
done
------------------------------------------
If you wanna run it hourly in cron, you shouldn't use the external endless while loop, because that loop prevents the script to go to an end, so cron will start a new endless script every hour.
the "$USE" > "60" seems don't work, use -gt.
remember to complete the 'echo' line with the 'mail' command piped (I removed it just to test the script without sending mail).
Ciao
Claudio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:19 AM
07-14-2003 06:19 AM
Re: FileSystemAlert Script
#!/usr/bin/ksh
mark=1
while [ $mark = 1 ]
do
df | grep -v Filesystem |
while read line
do
MTP=$(echo "$line" | awk '{print $6}')
USE=$(echo "$line" | awk '{print $5}' | sed 's/.$//g')
if [ "$USE" > "60" ]
then
echo "$MTP $USE " | mailx -s "FS alert" sendto@work.com
sleep 100 #or whatever time
else
sleep 100 #or whatever time
fi
done
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:21 AM
07-14-2003 06:21 AM
Re: FileSystemAlert Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:27 AM
07-14-2003 06:27 AM
Re: FileSystemAlert Script
sorry...
anyway ... i would use the BASH shell not sh. That's what I originally scripted this in. (I put ksh in one of the last posts becuase I'm losing it today... i need a vacation) try not putting any shell interpreter in the first line or if you do try using
#!/bin/bash
Also ... do you get any error messeges in your code.. also putting this in cron might not be the best way to launch it.... i would put it in your startup scripts when the system starts. Then you don't need to worry about cron
once again.. sorry for all the posts... it's just been a really rough couple of days for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:46 AM
07-14-2003 06:46 AM
Re: FileSystemAlert Script
To all, i'll try suggestions from your posts in a minute. I wasn't getting any errors, it just wasn't running. I believe one of you said the way i had the script it would create an endless script every hour, which i believe it was when i looked at my processes! I'll respond back in a few. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:55 AM
07-14-2003 06:55 AM
Re: FileSystemAlert Script
to change that either 1 of 2 things can be done.
1 - enter it into your start up scripts on your box
2 - remove the folloing lines:
mark=1
while [ $mark = 1 ]
do
#and also
sleep 100 #or whatever time
else
sleep 100 #or whatever time
#and also
done #which is the last line which closes the while [$mark = 1 ] line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 11:49 AM
07-14-2003 11:49 AM
Re: FileSystemAlert Script
You can start the script as he if you will
start it in the boot by adding link to him
to the runlevel that you work in.
ln -s <script path> /sbin/rcX.d/S998diskcheck
Caesar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 11:50 AM
07-14-2003 11:50 AM
Re: FileSystemAlert Script
You can start the script as he if you will
start it in the boot by adding link to him
to the runlevel that you work in.
ln -s <script path>
/etc/rc.d/rcX.d/S998diskcheck
Caesar