1833851 Members
2174 Online
110063 Solutions
New Discussion

Re: Script Query

 
Hunki
Super Advisor

Script Query

I have this script which is suppose to page me if a certain number of processes are less than 7 and it shud page me at either the 16:00 hrs or 08:00 hrs time period ( this is according to my cron job )

Is this if statement enough to fulfill my need, coz lately its been paging me out at 08:00 hrs even though the number of processes are 7 , can somebody let me know why its behaving like this.

Here is the condition that I am putting in :

if [ $gv -lt 7 -a \( $gv2 -eq 16 -o $gv2 -eq 8 \) ]
5 REPLIES 5
Jonathan Fife
Honored Contributor

Re: Script Query

That particular statement looks correct. Perhaps the variable assignment to gv isn't being done correctly...
Decay is inherent in all compounded things. Strive on with diligence
Peter Godron
Honored Contributor

Re: Script Query

Hunki,
also ensure you have white spaces around your escaped brackets. You could add a second set of brackets around the internal expression:
if [ \( $gv -lt 7 \) -a \( \( $gv2 -eq 16 \) -o \( $gv2 -eq 8 \) \) ]
Hunki
Super Advisor

Re: Script Query

I have made on small change now :

if [ \( $gv -lt 7 \) -a \( $gv2 -eq 16 -o $gv2 -eq 8 \) ]

Also after debugging the value picked up by gv and gv2 is correct.

Lets c how its goes tdy and tomm.
spex
Honored Contributor

Re: Script Query

Hi Hunki,

if [ $gv -lt 7 -a \( $gv2 -eq 16 -o $gv2 -eq 8 \) ]; then
ps -ef | grep > /tmp/proclist.text

...
fi

Then consult /tmp/proclist.text the next time you are paged to see exactly was was running at the time.

PCS
Mancboy
Valued Contributor

Re: Script Query

Hunki, what shell are you using?
-a and -o are for checking on filetypes.

in ksh the following works fine:

if [[ $gv -lt 7 && ($gv2 -eq 16 || $gv2 -eq 8) ]]
then
page hunki
fi

or you could always use perl or awk and not have to bother about [ or [[ or ( or (( or \(