LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Issue with Script?? (http://www.linuxquestions.org/questions/linux-newbie-8/issue-with-script-648489/)

linuxshadow 06-11-2008 01:18 AM

Issue with Script??
 
root@testdb /]# cat /u01/BACKUP/scripts/filespace.sh
#!/bin/bash
# This script can be used to
# warn the users that
# the file system is getting full
#
# Script needs adjusted for your
# needs. Below is set to monitor
# all the file systems mounted and report to
# RECEIVER
#
# Usage: as a cron entry for best use.


RECEIVER=ITOPS.SSI@oracle.com

for fs in `df -k|awk '{print $1}'|sed -n "3,14 p"`
do
x=`df -kl | grep $fs | awk '{ print $5 }'`
y=50%

if [ $x -gt $y ]
then
message="File System `df -k |grep $fs |awk '{print $6\",\"$5}'` Full!!!"
echo $subject
echo $message | mailx -s "`hostname` - File System Full
Warning !!!" $RECEIVER
fi
done
[root@testdb /]#
-----------------------------------

[root@testdb /]# ./u01/BACKUP/scripts/filespace.sh
./u01/BACKUP/scripts/filespace.sh: line 21: [: 12%: integer expression expected
./u01/BACKUP/scripts/filespace.sh: line 21: [: 0%: integer expression expected
./u01/BACKUP/scripts/filespace.sh: line 21: [: 2%: integer expression expected
./u01/BACKUP/scripts/filespace.sh: line 21: [: 96%: integer expression expected
./u01/BACKUP/scripts/filespace.sh: line 21: [: 91%: integer expression expected
[root@testdb /]#

How to i resolve this error.

--

jpwigan 06-11-2008 01:28 AM

-gt expects numeric inputs. "50%" is not a numeric input, but "50" is. You need to strip the % sign out of your input before testing against it.

So, instead of:

y=50%

You would use:

y=50

and to strip the % out in the x line, add a pipe to your favorite regex engine. My example uses sed:

x=`df -kl | grep $fs | awk '{ print $5 }' | sed 's/%//'`

For perl, it's identical except for the command:

x=`df -kl | grep $fs | awk '{ print $5 }' | perl -pe 's/%//'`


All times are GMT -5. The time now is 06:52 AM.