Unix Shell - test integer value - ksh

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2007 > test integer value - ksh





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author test integer value - ksh
Moussa Razzouki

2007-02-27, 7:21 am

Hi, I'm stuck on testing some integer values within a script that
checks filesystem usage.
Whatever I do, the -ge operator seems not to work. Driving me crazy,
just cant see where the problem is.
Need a clue!

This is the script I made so far:

#!/bin/ksh
mailout ()
{
echo $suj
}

_attnlimit=80
_alertlimit=90
SNE=$(uname -n)
_sysfilesystems="/ /usr /var /home /tmp"

for fs in $_sysfilesystems
do
echo size = $size
size=$(df $fs|grep $fs|awk '{ print $4; }'|sed -e 's/%//g')

if [[ $size -ge $attnlimit ]]
then
suj="ATTN: ${SNE}:$fs reached ${size}%"
mailout
fi
if [[ $size -ge $alertlimit ]]
then
suj="ALERT: ${SNE}:$fs reached ${size}% !!"
mailout
fi
done

Now this is the output, notice it echo's all values where it should
only pick up the 84% (/home):

HST root /util/sysbeh # ./dusage.sh
size =
ATTN: HST:/ reached 27%
ALERT: HST:/ reached 27% !!
size = 27
ATTN: HST:/usr reached 72%
ALERT: HST:/usr reached 72% !!
size = 72
ATTN: HST:/var reached 25%
ALERT: HST:/var reached 25% !!
size = 25
ATTN: HST:/home reached 84%
ALERT: HST:/home reached 84% !!
size = 84
ATTN: HST:/tmp reached 7%
ALERT: HST:/tmp reached 7% !!

Bo Yang

2007-02-27, 7:21 am

Moussa Razzouki :
> Hi, I'm stuck on testing some integer values within a script that
> checks filesystem usage.
> Whatever I do, the -ge operator seems not to work. Driving me crazy,
> just cant see where the problem is.
> Need a clue!
>
> This is the script I made so far:
>
> #!/bin/ksh
> mailout ()
> {
> echo $suj
> }
>
> _attnlimit=80
> _alertlimit=90
> SNE=$(uname -n)
> _sysfilesystems="/ /usr /var /home /tmp"
>
> for fs in $_sysfilesystems
> do
> echo size = $size
> size=$(df $fs|grep $fs|awk '{ print $4; }'|sed -e 's/%//g')
>
> if [[ $size -ge $attnlimit ]]
> then
> suj="ATTN: ${SNE}:$fs reached ${size}%"
> mailout
> fi
> if [[ $size -ge $alertlimit ]]
> then
> suj="ALERT: ${SNE}:$fs reached ${size}% !!"
> mailout
> fi
> done
>
> Now this is the output, notice it echo's all values where it should
> only pick up the 84% (/home):
>
> HST root /util/sysbeh # ./dusage.sh
> size =
> ATTN: HST:/ reached 27%
> ALERT: HST:/ reached 27% !!
> size = 27
> ATTN: HST:/usr reached 72%
> ALERT: HST:/usr reached 72% !!
> size = 72
> ATTN: HST:/var reached 25%
> ALERT: HST:/var reached 25% !!
> size = 25
> ATTN: HST:/home reached 84%
> ALERT: HST:/home reached 84% !!
> size = 84
> ATTN: HST:/tmp reached 7%
> ALERT: HST:/tmp reached 7% !!
>

I am afraid you define two variables _attnlimit and _alertlimit, but
use them as attnlimit and alertlimit!


jambesh@gmail.com

2007-02-27, 7:21 am

On Feb 27, 3:04 pm, "Moussa Razzouki" <mous...@gmail.com> wrote:
> Hi, I'm stuck on testing some integer values within a script that
> checks filesystem usage.
> Whatever I do, the -ge operator seems not to work. Driving me crazy,
> just cant see where the problem is.
> Need a clue!
>
> This is the script I made so far:
>
> #!/bin/ksh
> mailout ()
> {
> echo $suj
>
> }
>
> _attnlimit=80
> _alertlimit=90
> SNE=$(uname -n)
> _sysfilesystems="/ /usr /var /home /tmp"
>
> for fs in $_sysfilesystems
> do
> echo size = $size
> size=$(df $fs|grep $fs|awk '{ print $4; }'|sed -e 's/%//g')
>
> if [[ $size -ge $attnlimit ]]
> then
> suj="ATTN: ${SNE}:$fs reached ${size}%"
> mailout
> fi
> if [[ $size -ge $alertlimit ]]
> then
> suj="ALERT: ${SNE}:$fs reached ${size}% !!"
> mailout
> fi
> done
>
> Now this is the output, notice it echo's all values where it should
> only pick up the 84% (/home):
>
> HST root /util/sysbeh # ./dusage.sh
> size =
> ATTN: HST:/ reached 27%
> ALERT: HST:/ reached 27% !!
> size = 27
> ATTN: HST:/usr reached 72%
> ALERT: HST:/usr reached 72% !!
> size = 72
> ATTN: HST:/var reached 25%
> ALERT: HST:/var reached 25% !!
> size = 25
> ATTN: HST:/home reached 84%
> ALERT: HST:/home reached 84% !!
> size = 84
> ATTN: HST:/tmp reached 7%
> ALERT: HST:/tmp reached 7% !!


################################### check this condition if [[ $size
-ge $attnlimit ]] also if [[ $size -ge $alertlimit ]] here
you have used wrong variable name $attnlimit and $alertlimit it should
be start with underscore( _ ) as you have defined it earlier.

Moussa Razzouki

2007-02-27, 7:21 am

On 27 feb, 13:20, jamb...@gmail.com wrote:
> On Feb 27, 3:04 pm, "Moussa Razzouki" <mous...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
> ################################### check this condition if [[ $size
> -ge $attnlimit ]] also if [[ $size -ge $alertlimit ]] here
> you have used wrong variable name $attnlimit and $alertlimit it should
> be start with underscore( _ ) as you have defined it earlier.



Who's gonna shoot me.. I'll line up bravely.
Seriously, these things always happen to me (so simple, so stupid).
Have been fiddling with it for at least 30 minutes.

I've read somewhere that using underscores in variables is a good
habbit,
this for possible conflict with built-in shell vars. Sigh.

Ty.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com