LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-27-2012, 02:10 AM   #1
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Rep: Reputation: Disabled
Limiting the script


Greetings

Last edited by manju98458; 12-04-2012 at 03:42 AM.
 
Old 11-27-2012, 02:12 AM   #2
eyanu
Member
 
Registered: Jul 2012
Location: kampala,Uganda
Distribution: backtrack
Posts: 87

Rep: Reputation: Disabled
Could you please post the script here, we've a look at it!!
 
Old 11-27-2012, 02:47 AM   #3
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
how can i do the code tag to share my script, it say too short to code tag
 
Old 11-27-2012, 02:48 AM   #4
eyanu
Member
 
Registered: Jul 2012
Location: kampala,Uganda
Distribution: backtrack
Posts: 87

Rep: Reputation: Disabled
You can wrap it in ""
Quote:
my code here
 
Old 11-27-2012, 02:50 AM   #5
eyanu
Member
 
Registered: Jul 2012
Location: kampala,Uganda
Distribution: backtrack
Posts: 87

Rep: Reputation: Disabled
As you're replying just above where there is "bold", underline there should be something like a notepad, and it's the last after link
 
Old 11-27-2012, 02:53 AM   #6
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
This is my script

Last edited by manju98458; 12-04-2012 at 03:18 AM.
 
Old 11-27-2012, 03:04 AM   #7
eyanu
Member
 
Registered: Jul 2012
Location: kampala,Uganda
Distribution: backtrack
Posts: 87

Rep: Reputation: Disabled
OK, i've also set up a cron to execute every 17 minutes and i'll be monitoring it, however make sure to close off your script with an fi at the end of it all, use:
Quote:
set -x
#!/bin/sh -x

#admin email account
ADMIN="abc@test.com"

# set usage alert threshold
THRESHOLD=85

#hostname
HOSTNAME=$(hostname)

#mail client
MAIL=/bin/mail

# store all disk info here
EMAIL=""

for line in $(df -hP | egrep '^/dev/' | awk '{ print $6 "_:_" $5 }')
do

part=$(echo "$line" | awk -F"_:_" '{ print $1 }')
part_usage=$(echo "$line" | awk -F"_:_" '{ print $2 }' | cut -d'%' -f1 )

if [ $part_usage -ge $THRESHOLD -a -z "$EMAIL" ];
then
EMAIL="$(date): Running out of diskspace on $HOSTNAME\n"
EMAIL="$EMAIL\n$part ($part_usage%) >= (Threshold = $THRESHOLD%)"

elif [ $part_usage -ge $THRESHOLD ];
then
EMAIL="$EMAIL\n$part ($part_usage%) >= (Threshold = $THRESHOLD%)"
fi
done

if [ -n "$EMAIL" ];
then
echo -e "$EMAIL" | $MAIL -s "Alert: Partition(s) almost out of diskspace on $HOS
TNAME" "$ADMIN"
fi
 
Old 11-27-2012, 03:06 AM   #8
eyanu
Member
 
Registered: Jul 2012
Location: kampala,Uganda
Distribution: backtrack
Posts: 87

Rep: Reputation: Disabled
In the mean time can you post results for
Quote:
df -hP | egrep '^/dev/' | awk '{ print $6 "_:_" $5 }'
when you run it on your terminal.
 
Old 11-27-2012, 03:18 AM   #9
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
Below is the output
Quote:
/_:_25%
/apps_:_42%
/tmp_:_4%
/var_:_7%
/home_:_5%
/user_:_31%
/usr_/local_:_62%
/boot_:_10%
 
Old 11-27-2012, 03:25 AM   #10
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,452

Rep: Reputation: 85
Quote:
Originally Posted by manju98458 View Post
Greetings.

i have script to monitor the disk space utilization in my linux server the script generate email when the disk uilization reaches to 85% and the cron is scheduled to monitor every 17 min. Both are fine but, the issue is that it will continousely generates email, is it possible to put limit on the script to generate the email only one time when the disk threshold reaches 85 % instead of multiple email alerts.
No need to do that. Linux has this already implemented this using disk quotas.

The package name on most distros is quota.

On my CentOS server:

Code:
[~]$ rpm -q quota                                                              
quota-3.17-16.el6.x86_64
[~]$
First search result from Google:

http://www.yolinux.com/TUTORIALS/Lin...ialQuotas.html

There's a nice video covering disk quotas by Robb Tracey for the Linux+ Exam study material.

Last edited by fakie_flip; 11-27-2012 at 03:27 AM.
 
Old 11-27-2012, 06:35 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
quota is for limiting users and/or groups in the amt of disk space they use.
This is not the same as worrying about the total disk space used....
 
Old 11-27-2012, 06:44 AM   #12
eyanu
Member
 
Registered: Jul 2012
Location: kampala,Uganda
Distribution: backtrack
Posts: 87

Rep: Reputation: Disabled
Hey, i've tested your script and it sends me mail every 15 mins to remind me of disk usage, however that's after i set the THRESHOLD to like 9. Am wondering when your THRESHOLD=85 why would it send you an email in the first place when your:
Quote:
df -hP | egrep '^/dev/' | awk '{ print $6 "_:_" $5 }'
returns:
Quote:
/_:_25%
/apps_:_42%
/tmp_:_4%
/var_:_7%
/home_:_5%
/user_:_31%
/usr_/local_:_62%
/boot_:_10%
 
Old 12-04-2012, 01:13 AM   #13
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
I am using the script to monitor the disk space of the folder. When the folder storage crosess more than 85 %
it will send an alert. So, it's generating the alert every 17 min. My utlimate aim is to limit the script to send the alert only one time instead of multiple alerts. For enabling the disk quota we dont have permission hence we are using the alert script in place to monitor.
 
Old 12-04-2012, 07:29 PM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Your OP (post #1) says 'Last edited by manju98458; Yesterday at 18:42. '
Now there is no script to look at; why did you delete it?

re script in post #7
Code:
set -x
#!/bin/sh -x
hash-bang must come first, and using -x twice is redundant. Try
Code:
#!/bin/bash
set -xv
@OP: you want it to email you 'once'; define 'once' ie once per hr, per day, per week, per year ???

Please post your current version of the script and confirm the threshold and actual disk percentages.
As noted above, you claim threshold = 85, but your actual results as claimed don't have a number >= to that ...
 
Old 12-05-2012, 12:46 AM   #15
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
chris,script is same as in #7 and cron is running every 17 min to monitor the disk folder. When the folder size reaches 85 % it should generate only one mail per hour.
 
  


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
Linux script Limiting Zip archive size giantanakim Programming 15 11-09-2011 12:59 PM
download manager script with bandwidth limiting steve51184 Linux - Server 1 08-03-2008 05:59 PM
Limiting the output of the script Breezend Programming 2 12-06-2006 02:15 PM
Limiting RAM usage in a perl script DanTaylor Programming 2 05-05-2006 03:37 PM
limiting page load frequency with a perl cgi script Metroid Programming 0 12-30-2004 11:33 PM


All times are GMT -5. The time now is 05:58 AM.

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