?
Solved

if null then

Posted on 2006-06-01
14
Medium Priority
?
1,937 Views
Last Modified: 2008-01-09
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
Comment
Question by:bkreynolds48
  • 3
  • 3
  • 3
  • +2
13 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 16807889
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
 
LVL 1

Author Comment

by:bkreynolds48
ID: 16807908
Yes, I changed that but still no luck.
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 16807988
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:bira
ID: 16808265
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
 
LVL 1

Author Comment

by:bkreynolds48
ID: 16808577
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
 
LVL 48

Expert Comment

by:Tintin
ID: 16812063
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
 
LVL 38

Expert Comment

by:yuzh
ID: 16812655
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
 
LVL 48

Expert Comment

by:Tintin
ID: 16812815
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
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 16812854
Hi Tintin, yuzh,

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


Kent
0
 
LVL 48

Expert Comment

by:Tintin
ID: 16813054
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
 
LVL 38

Expert Comment

by:yuzh
ID: 16813490
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
 
LVL 1

Author Comment

by:bkreynolds48
ID: 16816885
I did not know how to split the points - should be split between yuzh  and Tintin

Thanks to you both
0
 
LVL 38

Accepted Solution

by:
yuzh earned 1500 total points
ID: 16833536
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question