LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2008, 04:19 PM   #1
cat555
LQ Newbie
 
Registered: Nov 2008
Posts: 12

Rep: Reputation: 0
trying to create shell script to monitor logfile size and email an alert message


I am trying to create a shell script that will do a df -h on datafiles, if they are more then 80% full, I want it to send me an email alert message. I have a script that will check my mount points and send me a report once a day, but I need to be more proactive because these will fill really quickly when some jobs are running and they can lock up the database before you know what is going on.
Thanks for any suggestions and help
 
Old 11-11-2008, 05:29 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,670

Rep: Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487
You've got various options:
1. use cron more frequently eg every 5 mins.
2. Get the controlling job to spawn off a checking script when it starts
3. get the output job to do its own data checking

etc. It depends on the lang and exactly how your app works.
 
Old 11-12-2008, 11:16 AM   #3
cat555
LQ Newbie
 
Registered: Nov 2008
Posts: 12

Original Poster
Rep: Reputation: 0
What I was looking to do was to create the script, have it cron'd to run every 5 minutes and only send me an alert when one of the mount points was filling up, so just when one of the datafiles was getting over 80%. One of the problems I am running into is that the servers have multiple files and I get into a loop. What I have so far is

df -h | grep oradata | awk '{ print $4 " " $5 }' output
if output $4 >= 80
then
mail -s "Alert: File filling up" $me
else
fi
As you can tell I have forgotten a lot ...
Another problem to this is that I need the alert message to identify which file and which host.
any help is greatly appreciated
thanks
 
Old 11-13-2008, 01:59 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,670

Rep: Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487
You need something like this
Code:
for pcent in `df -h | grep oradata | awk '{ print $5 }' |cut -d'%' -f1`
do
    if [[ $pcent -ge 80 ]]
    then
        host=`hostname`
        mail -s "Alert: partition $pcent full on $host"  you@domain-name.com
    fi
done
note that df tells you how full a disk (actually a partition) is. You can't use it on a file.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell scripting: Print output to logfile, error to logfile & screen stefanlasiewski Programming 18 05-22-2008 12:47 PM
LXer: Perl script to monitor disk space and send an email alert LXer Syndicated Linux News 1 02-23-2007 01:12 PM
Writing shell script with mail < logfile humbletech99 Programming 2 11-22-2005 08:20 AM
Bash script to alert by email 3 times then stop. pmpc00 Linux - General 2 11-04-2004 07:23 AM
how to produce pop-up message box / alert window from shell script peb Linux - Newbie 3 02-25-2004 03:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration