Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i fix this file in order to received the necessary e-mail messages ??

Status
Not open for further replies.

chijar

Technical User
Dec 26, 2012
7
US
dear all.
i'm a dba and i'm newbie with awk but im ready to give up with this --> :S .
So, i want to schedule a task in crontab at solaris that send e-mail message ONLY if the amount of GB in my filesystems exceeds the threshold configured.

The problem is that every execution (either exceeds or no the threshold) i receive an e-mail message, and ONLY i have to received message if the GB used is more than threshold that i putted.


Here are my lines of my script sh:
#------------------------------------START----------------------------------------
FEC_REPORT=`date "+%m/%d/%y %k:%M"`
export MAILTO="algo@dominio.com"

FS_LIMIT=$1

FS_GT=`df -k|grep -v boot|grep -v shm|awk '{print $5" "$6}' |/usr/xpg4/bin/awk -F"%" -v fs_limit=${FS_LIMIT} '$1 > fs_limit {print $1"%--->"$2}'`
if [ -n "${FS_GT}" ]
then
echo "${FS_GT}"|mailx -s "EMPRESA : File systems on `hostname` reached ${FS_LIMIT} USED: ${FEC_REPORT}" ${MAILTO}
fi
#--------------------------------------END--------------------------------------

i executed the script in this way: script.sh 80, where 80 is the threshold.

Please i need your help.
Thanks.
zipimon
 
And which unexpected message do you receive ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV
thanks for your answers but i want to know how can i fix or change something in script in order to receive ONLY e-mail messages when the threshold value exceeds.
If the threshold value doesnt exceeds i wont receive an e-mail.
Actually either the threshold exceeds or no i received an e-mail.

Hopefully you can help me
thanks again
 

Try this:
Code:
FEC_REPORT=`date "+%m/%d/%y %k:%M"`
export MAILTO="algo@dominio.com"

FS_LIMIT=$1

FS_GT=`df -k|grep -v boot|grep -v shm|awk '{print $5" "$6}' |/usr/xpg4/bin/awk -F"%" -v fs_limit=${FS_LIMIT} '$1 > fs_limit {print $1"%--->"$2}'`
if [ -n "${FS_GT}" ]
then
  echo "${FS_GT}"|mailx -s "EMPRESA : File systems on `hostname` reached ${FS_LIMIT} USED: ${FEC_REPORT}" ${MAILTO} 
fi
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thanks guy for your answer..
I changed (;) but unfortunatelly the behavior is the same. My code shows here:
Code:
FEC_REPORT=`date "+%m/%d/%y %k:%M"`
export MAILTO="algo@dominio.com"
FS_LIMIT=$1

FS_GT=`df -k|grep -v boot|grep -v shm|awk '{print $5" "$6}' |/usr/xpg4/bin/awk -F"%" -v fs_limit=${FS_LIMIT} '$1 > fs_limit {print $1"%--->"$2}'`
if [ -n "${FS_GT}" ]
then
echo "${FS_GT}"|mailx -s "Empresa : File systems  on `hostname` reached ${FS_LIMIT} USED: ${FEC_REPORT}" ${MAILTO}
fi

My OS is : SunOS HOSTNAME 5.10 Generic_142901-03 i86pc i386 i86pc

more ideas ??? :(
 
Again, give us an example of unexpected message received in order to discover why awk isn't filtering properly.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thanks PHV for your answer.
Humm i try to explain my issue :


1.- /opt --> 81 used.
2.- If i executed:
2.1.- script.sh 85 <ENTER>
Result now: I receive an e-mail with that body:
capacity Mounted%--->
DESIRABLE RESULT: i Wont receive any e-mail. Why ?? because the threshold (85) is greater than the Gb used (81) in /opt File system.

2.2.- script.sh 80 <ENTER>
Result now: I receive an e-mail with that body:
capacity Mounted%--->
81%---> /opt
DESIRABLE RESULT: This. I mean if the threshold (80) is less than the Gb occuped (81) in /opt filesystem i will received an e-mail with details like this example.

Actually i received e-mail when the threshold is reached or passed and e-mail when the threshold is not reached too.
ONLY, I want to received e-mail messages when the threshold reached or passed.

I hope letting me understand.
thanks again
 
Replace this:
awk '{print $5" "$6}'
with this:
awk 'NR>1{print $5" "$6}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ooops sorry, I posted the wrong code.
Try this:
Code:
FEC_REPORT=`date "+%m/%d/%y %k:%M"`
export MAILTO="algo@dominio.com"

FS_LIMIT=$1

FS_GT=`df -k|grep -v boot|grep -v shm|awk '{print $5" "$6}' |/usr/xpg4/bin/awk -F"%" -v fs_limit=${FS_LIMIT} 'int($1) > int(fs_limit) {print $1"%--->"$2}'`
if [ -n "${FS_GT}" ]
then
  echo "${FS_GT}"|mailx -s "EMPRESA : File systems on `hostname` reached ${FS_LIMIT} USED: ${FEC_REPORT}" ${MAILTO}
fi
[noevil]
PS: notice the part:
Code:
"...int($1) > int(fs_limit) ..."



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thanks PHV for your help.
It works. !!!
 
thanks LKBrwnDBA for your answer too.

Only an additional question, now, the e-mail comes with its body :

88%---> /opt

but if i want to the e-mail comes with its head like this:


capacity Mounted%--->
88%---> /opt


it is possible to do that? how ??

Meanwhile i work with your advices but if u want i really appreciated if you can answer this question.
Thanks.
 


Change the "echo":
Code:
if [ -n "${FS_GT}" ]
then
  echo "\n\n\t\tCapacity Mounted% --->\n\t\t\t${FS_GT}"|  mailx -s "EMPRESA : File systems on `hostname` reached ${FS_LIMIT} USED: ${FEC_REPORT}" ${MAILTO}
fi
[medal]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
dear Lk
thanks but now the e-mail comes like this.
Code:
\n\n\t\tCapacity Mounted% --->\n\t\t\t88%---> /opt

any idea ??
thanks again
 
any idea ??
man echo

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top