1833210 Members
2922 Online
110051 Solutions
New Discussion

Script Query

 
Hunki
Super Advisor

Script Query

I have this script which I want to run :

#!/bin/ksh
# Script to monitor the IPC's count

Q1=`/usr/bin/ipcs -q|wc -l`
Q2=`/usr/bin/ipcs -s|wc -l`
Q3=`/usr/bin/ipcs -m|wc -l`

if [ Q1 -gt 140 ]
then
/usr/bin/mailx -s "xxx" hh@hh.com
fi

if [ Q2 -gt 120 ]
then
/usr/bin/mailx -s "xxx" hh@hh.com
fi

if [ Q3 -gt 300 ]
then
/usr/bin/mailx -s "xxx" hh@hh.com
fi

Can someone point out why its not running and how to make it run.

Thanks!
6 REPLIES 6
IT_2007
Honored Contributor

Re: Script Query

use set -x option after #!/bin/ksh line and execute so that you can see why it is not running.
A. Clay Stephenson
Acclaimed Contributor

Re: Script Query

wrong:
if [ Q1 -gt 140 ]

right (well, at least the syntax is correct):
if [ ${Q1} -gt 140 ]

If it ain't broke, I can fix that.
spex
Honored Contributor

Re: Script Query

Hi Hunki,

Aside from what Clay said, you're not specifying the absolute path to the 'wc' binary, as you are for other binaries. Also send a test message to hh@hh.com to rule mail transport problems out.

PCS
Ivan Ferreira
Honored Contributor

Re: Script Query

You need a message body, try this:

#!/bin/ksh
# Script to monitor the IPC's count

Q1=`/usr/bin/ipcs -q > /tmp/q1;wc -l /tmp/q1`
Q2=`/usr/bin/ipcs -s > /tmp/q2;wc -l /tmp/q2`
Q3=`/usr/bin/ipcs -m > /tmp/q1;wc -l /tmp/q3`

if [ Q1 -gt 140 ]
then
/usr/bin/mailx -s "xxx" hh@hh.com < /tmp/q1
fi

if [ Q2 -gt 120 ]
then
/usr/bin/mailx -s "xxx" hh@hh.com < /tmp/q2
fi

if [ Q3 -gt 300 ]
then
/usr/bin/mailx -s "xxx" hh@hh.com < /tmp/q3
fi
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Ivan Krastev
Honored Contributor

Re: Script Query

Maybe you should use full path for wc .

ivan
Peter Nikitka
Honored Contributor

Re: Script Query

Hi,

combine the solution of Clay and Ivan and it will work:
- use $Qn to get the value of a variable
- the mailx program reads from stdin
- set the PATH variable for cron scripts
E.g.

PATH=$PATH:/usr/bin
Qq=$(ipcs -q | wc -l | tee /tmp/Qq)
[ "$Qq" -gt 140 ] && mailx -s q_overflow hh@hh.com ...

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"