LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 12-15-2011, 11:35 AM   #1
Vi_rod
Member
 
Registered: Dec 2011
Posts: 42

Rep: Reputation: Disabled
Strange error for disk space alert email script


Hello, This script gives me a strange error after the mount was done on this server. (pasting the error at the bottom)
DATE=`date '+%Y%m%d'`
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 70 ]
then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" >/tmp/dfh.txt
df -H >> /tmp/dfh.txt
mail -s "$(hostname) -:- Alert: Level 1. Almost out of disk space $usep%" aabb@ld.com < /tmp/dfh.txt
elif [ $usep -ge 80 ]
then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" >/tmp/dfh.txt
df -H >> /tmp/dfh.txt
mail -s "$(hostname) -:- Alert: Level 2. Almost out of disk space $usep%" abc@se.com < /tmp/dfh.txt
elif [ $usep -ge 90 ]
then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" >/tmp/dfh.txt
df -H >> /tmp/dfh.txt
mail -s "$(hostname) -:- Alert: Level 3. Disk Space critical - Almost out of disk space $usep%" abc@kk.com < /tmp/dfh.txt
fi


done


ERROR -


/memory_status_alert.sh: line 10: [: -ge: unary operator expected
./memory_status_alert.sh: line 15: [: -ge: unary operator expected
./memory_status_alert.sh: line 20: [: -ge: unary operator expected
/dataman/proddb_bkp
./memory_status_alert.sh: line 10: [: /ataman/db_bkp: integer expression expected
./memory_status_alert.sh: line 15: [: /ataman/db_bkp: integer expression expected
./memory_status_alert.sh: line 20: [: /ataman/db_bkp: integer expression expected

./memory_status_alert.sh: line 10: [: -ge: unary operator expected
./memory_status_alert.sh: line 15: [: -ge: unary operator expected
./memory_status_alert.sh: line 20: [: -ge: unary operator expected
/dataman/prodapp_bkp
./memory_status_alert.sh: line 10: [: /ataman/app_bkp: integer expression expected
./memory_status_alert.sh: line 15: [: /ataman/app_bkp: integer expression expected
./memory_status_alert.sh: line 20: [: /ataman/app_bkp: integer expression expected


IF df -h is run independantly this is what i get -

Filesystem Size Used Avail Use% Mounted on
/dev/sda3 29G 11G 17G 38% /
/dev/sda6 84G 70G 11G 88% /opt
/dev/sda2 29G 8.7G 19G 33% /home
/dev/sda1 190M 19M 162M 11% /boot
tmpfs 1.7G 0 1.7G 0% /dev/shm
192.168.2.7:/DataVolume/proddb_bkp
915G 433G 482G 48% /atamandb_bkp
192.168.2.7:/DataVolume/prodapp_bkp
915G 433G 482G 48% /ataman/app_bkp

Cant get the problem!! please help!
 
Old 12-15-2011, 11:49 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 243Reputation: 243Reputation: 243
It bugs when $usep is not a number, maybe from

192.168.2.7:/DataVolume/proddb_bkp
915G 433G 482G 48% /atamandb_bkp
192.168.2.7:/DataVolume/prodapp_bkp
915G 433G 482G 48% /ataman/app_bkp

df lines output
 
1 members found this post helpful.
Old 12-15-2011, 01:59 PM   #3
asimba
Member
 
Registered: Mar 2005
Location: 127.0.0.0
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
I am unable to get "output" - where are we getting it from
Code:
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
 
Old 12-15-2011, 08:08 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Basically those errors are saying that $usep is not being correctly extracted for use in the 'if' statements.
Try these 2 suggestions

1. add
Code:
set -xv
to the top of the script; it'll show you exactly what the parser is doing/seeing

2. http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS ie [[ ]] is more robust than [ ]
 
1 members found this post helpful.
Old 12-15-2011, 08:23 PM   #5
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 243Reputation: 243Reputation: 243
Quote:
Originally Posted by asimba View Post
I am unable to get "output" - where are we getting it from
Code:
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
Maybe your $LANG is not set to english or us language ?
Try :
Code:
LC_ALL=C df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }'
 
Old 12-16-2011, 12:41 AM   #6
Vi_rod
Member
 
Registered: Dec 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01 View Post
Basically those errors are saying that $usep is not being correctly extracted for use in the 'if' statements.
Try these 2 suggestions

1. add
Code:
set -xv
to the top of the script; it'll show you exactly what the parser is doing/seeing

2. http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS ie [[ ]] is more robust than [ ]


I changed [] to [[ ]], and did set -xv, somehow it does send me a mail when the script is run and alert matches but still gives me the same error.

This is the output i get when set -xv is done -
+ df -H
+ grep -vE '^Filesystem|tmpfs|cdrom'
+ awk '{ print $5 " " $6 }'
+ read output
+ echo 39% /
39% /
echo $output | awk '{ print $1}' | cut -d'%' -f1
++ echo 39% /
++ cut -d% -f1
++ awk '{ print $1}'
+ usep=39
echo $output | awk '{ print $2 }'
++ echo 39% /
++ awk '{ print $2 }'
+ partition=/
+ [[ 39 -ge 70 ]]
+ [[ 39 -ge 80 ]]
+ [[ 39 -ge 90 ]]
+ read output
+ echo 88% /opt
88% /opt
echo $output | awk '{ print $1}' | cut -d'%' -f1
++ echo 88% /opt
++ awk '{ print $1}'
++ cut -d% -f1
+ usep=88
echo $output | awk '{ print $2 }'
++ echo 88% /opt
++ awk '{ print $2 }'
+ partition=/opt
+ [[ 88 -ge 70 ]]
hostname
++ hostname
date
++ date
+ echo 'Running out of space "/opt (88%)" on HOST as on Fri Dec 16 11:02:24 IST 2011'
+ df -H
hostname
++ hostname
+ mail -s 'HOST -:- Alert: Level 1 reached. Almost out of disk space 88%' ooee@ei.com
+ read output
+ echo 33% /home
33% /home
echo $output | awk '{ print $1}' | cut -d'%' -f1
++ echo 33% /home
++ awk '{ print $1}'
++ cut -d% -f1
+ usep=33
echo $output | awk '{ print $2 }'
++ echo 33% /home
++ awk '{ print $2 }'
+ partition=/home
+ [[ 33 -ge 70 ]]
+ [[ 33 -ge 80 ]]
+ [[ 33 -ge 90 ]]
+ read output
+ echo 11% /boot
11% /boot
echo $output | awk '{ print $1}' | cut -d'%' -f1
++ echo 11% /boot
++ awk '{ print $1}'
++ cut -d% -f1
+ usep=11
echo $output | awk '{ print $2 }'
++ echo 11% /boot
++ awk '{ print $2 }'
+ partition=/boot
+ [[ 11 -ge 70 ]]
+ [[ 11 -ge 80 ]]
+ [[ 11 -ge 90 ]]
+ read output
+ echo

echo $output | awk '{ print $1}' | cut -d'%' -f1
++ echo
++ awk '{ print $1}'
++ cut -d% -f1
+ usep=
echo $output | awk '{ print $2 }'
++ echo
++ awk '{ print $2 }'
+ partition=
+ [[ '' -ge 70 ]]
+ [[ '' -ge 80 ]]
+ [[ '' -ge 90 ]]
+ read output
+ echo /ataman/db_bk
/ataman/db_bk
echo $output | awk '{ print $1}' | cut -d'%' -f1
++ echo /ataman/db_bk
++ awk '{ print $1}'
++ cut -d% -f1
+ usep=/ataman/db_bk
echo $output | awk '{ print $2 }'
++ echo /ataman/db_bk
++ awk '{ print $2 }'
+ partition=
+ [[ /ataman/db_bk -ge 70 ]]
./dd.sh: line 12: [[: /ataman/db_bk: syntax error: operand expected (error token is "/ataman/db_bk")
+ [[ /ataman/db_bk -ge 80 ]]
./dd.sh: line 17: [[: /ataman/db_bk: syntax error: operand expected (error token is "/ataman/db_bk")
+ [[ /ataman/db_bk -ge 90 ]]
./dd.sh: line 22: [[: /ataman/db_bk: syntax error: operand expected (error token is "/ataman/db_bk")
+ read output
+ echo
 
Old 12-16-2011, 05:04 AM   #7
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 243Reputation: 243Reputation: 243
See ? The bug comes from the long lines :

192.168.2.7:/DataVolume/proddb_bkp
915G 433G 482G 48% /atamandb_bkp
192.168.2.7:/DataVolume/prodapp_bkp
915G 433G 482G 48% /ataman/app_bkp

df seems to break long lines with new lines

try add the -P df option (posix portability) which should avoid that

So the second line of script should be:
Code:
df -H -P | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
 
1 members found this post helpful.
Old 12-16-2011, 07:09 AM   #8
Vi_rod
Member
 
Registered: Dec 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
thanx!!
 
  


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
OPENNMS -how can i get disk space alert & memory alert BY MAIL saravanakumar Linux - Server 11 05-30-2014 09:45 AM
[SOLVED] hard disk space email notification - SOLARIS 10 - script dlugasx Solaris / OpenSolaris 1 06-24-2010 07:49 AM
script for disk space alert cmontr Programming 2 01-12-2009 01:27 PM
Strange Insufficient Disk Space Error in Firefox zzyzcx Linux - Software 3 04-20-2008 02:18 PM
LXer: Perl script to monitor disk space and send an email alert LXer Syndicated Linux News 1 02-23-2007 02:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:38 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