use of "if" statement [message #439014] |
Wed, 13 January 2010 10:58 |
divroro12
Messages: 105 Registered: March 2008 Location: Laurel, MD USA
|
Senior Member |
|
|
Hi,
I'm writing a script that's supposed to send an email to me only if there are specific entries within a particular file. I already got entries into this file both from grepping another file & through echo, so now i want just specific information to be sent to me from the file.
The code should be something like this :
if the letters X,Y,Z are found within myfile.lst;
then mailx -s $MAIL_LIST < myfile.lst.
Please kindly help with this.
Regards,
- divroro12 -
|
|
|
|
Re: use of "if" statement [message #439020 is a reply to message #439014] |
Wed, 13 January 2010 11:12 |
divroro12
Messages: 105 Registered: March 2008 Location: Laurel, MD USA
|
Senior Member |
|
|
I'm writing a script for monitoring Oracle databases, so i presume it has SOMETHING to do with Oracle & i thought i posted this under the Linux/UNIX/shell scripting section of the forum.
Must my posting be only on Oracle specific issues?
- divroro12 -
|
|
|
Re: use of "if" statement [message #439024 is a reply to message #439020] |
Wed, 13 January 2010 12:00 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote:
Unix
Oracle Installation, [Oracle] Configuration, [Oracle] Troubleshooting and [Oracle] Scripting on Unix platforms (Solaris, HP-UX, AIX, etc.)
http://www.orafaq.com/Welcome to The Oracle FAQ
The Oracle FAQ is NOT an official Oracle Support site...
Forum Guide
How to get a quick answer to your question?
Before you decide to open a new topic, you should ask yourself:
...
Is my question specific to the Oracle database? Now, that may seem obvious since this site is called Oracle FAQs, but we get quite a few questions about Access and MS SQL Server here - and SQL between databases is not always compatible - so please ask any non-Oracle questions elsewhere. It will be to your advantage.
[Updated on: Wed, 13 January 2010 12:05] Report message to a moderator
|
|
|
|
Re: use of "if" statement [message #439055 is a reply to message #439045] |
Wed, 13 January 2010 16:25 |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
True, this type of stript can be adapted to many technologies, but it's a very common requirement for Oracle scripting. This (untested) snippet should get you started...
#!/usr/bin/ksh
U=scott
P=tiger
DB=devdb
TO=abc@xyz.com,def@xyz.com
LOG=/tmp/my_log.log
ORAERR="ORA-|Not connected"
ERR=0
sqlplus -s /nolog <<EOF >$LOG
connect $U/$P@$DB
--whenever sqlerror exit 1
-- some SQL...
select ... from ...;
exit;
EOF
if [ $? -ne 0 ]; then ERR=1; echo "ERROR: Oracle SQLplus error"; fi
# Check for ORA- error codes
cnt=`egrep -c "$ORAERR" $LOG`
if [ $cnt -gt 0 ]; then ERR=1; echo "ERROR: Oracle error code found cnt=$cnt"; fi
# Alert for any failure
if [ $ERR -ne 0 ]; then
SUBJ="ERROR: Script failure `hostname` `basename $0`"
mailx -s "$SUBJ" $TO <$LOG
echo "Sent failure email..."
exit 1
fi
exit 0
[Updated on: Wed, 13 January 2010 16:29] Report message to a moderator
|
|
|
Re: use of "if" statement [message #441567 is a reply to message #439014] |
Mon, 01 February 2010 23:34 |
oratab
Messages: 5 Registered: April 2008 Location: Atlanta and/or Kansas Cit...
|
Junior Member |
|
|
The question was not very specific, when you say you want to
check for letters X,Y,Z in a file... so I will just show
a check for the 3-letter string "XYZ" in your file.
#-- This CAN be a simple as:
if grep "XYZ" myfile.lst >/dev/null
then mailx -s $MAIL_LIST < myfile.lst
fi
#-- unix shell-scripts use "fi" to mean "end if"
#-- If you meant to check to see if X or Y or Z is
#-- found anywhere in your file, then try:
if egrep "X|Y|Z" myfile.lst >/dev/null
then mailx -s $MAIL_LIST < myfile.lst
fi
|
|
|