LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Limiting the script (https://www.linuxquestions.org/questions/linux-newbie-8/limiting-the-script-4175438866/)

manju98458 11-27-2012 01:10 AM

Limiting the script
 
Greetings

eyanu 11-27-2012 01:12 AM

Could you please post the script here, we've a look at it!!

manju98458 11-27-2012 01:47 AM

how can i do the code tag to share my script, it say too short to code tag

eyanu 11-27-2012 01:48 AM

You can wrap it in ""
Quote:

my code here

eyanu 11-27-2012 01:50 AM

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

manju98458 11-27-2012 01:53 AM

This is my script

eyanu 11-27-2012 02:04 AM

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

eyanu 11-27-2012 02:06 AM

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.

manju98458 11-27-2012 02:18 AM

Below is the output
Quote:

/_:_25%
/apps_:_42%
/tmp_:_4%
/var_:_7%
/home_:_5%
/user_:_31%
/usr_/local_:_62%
/boot_:_10%

fakie_flip 11-27-2012 02:25 AM

Quote:

Originally Posted by manju98458 (Post 4837721)
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.

chrism01 11-27-2012 05:35 AM

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....

eyanu 11-27-2012 05:44 AM

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%

manju98458 12-04-2012 12:13 AM

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.

chrism01 12-04-2012 06:29 PM

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 ...

manju98458 12-04-2012 11:46 PM

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.


All times are GMT -5. The time now is 05:54 PM.