• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1939
  • Last Modified:

if null then

I have a script that is NOT working correctly.  I want the script to email me if the string is null:
=================
#!/bin/ksh
#
DBA1='bkr@yahoo.com' ;export DBA1
#
MSGLOG=/usr/local/dev.log
#
CHK=`rsh dev11 ps -ef |grep pmon |awk '{print $9}' |cut -d'_' -f3`
while  [ -z "$CHK" ]
do
  echo " ORACLE  is DOWN"                                        > $MSGLOG
  /usr/bin/date                                                         >> $MSGLOG
  /bin/mailx -s "**** ORACLE is DOWN ****" $DBA1 >> $MSGLOG
done
=================
The script writes to the log, never sends an email and never exits.

Any help would be greatly appreciated.
0
bkreynolds48
Asked:
bkreynolds48
  • 3
  • 3
  • 3
  • +2
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi bkreynolds48,

CHK is not set in the while loop so once the loop is entered it will never exit.

If you're trying to send the contents of MSGLOG as the mail body, you need to pipe or redirect the contents into mail, not out from.

  /bin/mailx -s "**** ORACLE is DOWN ****" $DBA1 < $MSGLOG


Good Luck!
Kent
0
 
bkreynolds48Author Commented:
Yes, I changed that but still no luck.
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi bkreynolds48,

Have you tested to see if you can send mail to that address?

mailx -s"Test Mail" bkr@yahoo.com < /usr/local/dev.log

Kent
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
biraCommented:
i suggest you to use this version of the script:

#!/bin/ksh
DBA1="bkr@yahoo.com" ;export DBA1
#
MSGLOG=/usr/local/dev.log
#
CHK=`ps -ef |grep pmon`
if [ $? != 0 ] ; then
  echo " ORACLE  is DOWN"  > $MSGLOG
  /usr/bin/date    >> $MSGLOG
mailx -s "**** ORACLE is DOWN ****"  $DBA1 <  $MSGLOG
fi
0
 
bkreynolds48Author Commented:
Sorry - had production crash - I'll try this script and see if it works - and yes I email the correct address all the time - just did not put the correct address in this text here.
Will get back to you by tomorrow - need to work on production first.
Thanks
0
 
TintinCommented:
Simply do:

#!/bin/ksh
[ -z "`rsh dev11 ps -ef |grep [p]mon`" ] && echo "ORACLE is DOWN\n`date`" | mailx -s "***** ORACLE is DOWN ****" bkr@yahoo.com
0
 
yuzhCommented:
You should not use "while" loop in the first place, when the sting is null, it will
loop forever,

make it looks like:

#!/bin/ksh
if [ -z ` rsh dev11 ps -ef |grep pmon | grep -v grep` ] ; then
   echo "ORACLE is DOWN\n`date`"  |\
   mailx -s "**** ORACLE is DOWN ****"  $DBA1
fi
exit

0
 
TintinCommented:
yuzh.

Your version is essentially a 5 line version of mine, except you have one important error.

You need quotes around the rsh command, otherwise when it returns nothing, it will be empty.
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi Tintin, yuzh,

rsh isn't universally used anymore.  The poster may not have it as an option.


Kent
0
 
TintinCommented:
Kdo.

The poster obviously does have rsh, as that is the command they are using in their original script.

Granted, it would be better if they were using ssh, but in terms of the solution, it makes no difference if they are using rsh or ssh.
0
 
yuzhCommented:
Tintin,
    thanks for your correction and have a nice weekend !

bkreynolds48,
    the correct version should be:
    #!/bin/ksh
if [ -z "` rsh dev11 ps -ef |grep pmon | grep -v grep`" ] ; then
   echo "ORACLE is DOWN\n`date`"  |\
   mailx -s "**** ORACLE is DOWN ****"  $DBA1
fi
exit
0
 
bkreynolds48Author Commented:
I did not know how to split the points - should be split between yuzh  and Tintin

Thanks to you both
0
 
yuzhCommented:
Hi bkreynolds48,

    Please read the instructtions in:
    http://www.experts-exchange.com/help.jsp#hi19
   and
   http://www.experts-exchange.com/help.jsp#hs5

   to learn how to split the ponits, it will help you to play around at EE, thanks and good night !

   yuzh
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now