Two parameters in a unix script param1 or not param2 then send email

I have the following lines in a script that is evaluating wrong.
I want to evaluate if PARAM1 or not PARAM2 then (do the then)  else (do the else)
The log does not have any of the PARAM1 but it has the PARAM2 and is  going to the "then'.


PARAM1=$(egrep -i -c "ORA-|rejected|Killed|skipped" "$log")
PARAM2=$(egrep -i -c "Server status = 0" "$log")
if [[ $PARAM1  -eq 0 || $PARAM2  -eq 0 ]]; then
    (cat $TXTERROR;uuencode $ATTFILE Coldbackup-log.txt) | mail -s "$SUBJECT" $M
AILTO
else
    (cat $TXTDEPLOY;uuencode $ATTFILE Coldbackup-log.txt) | mail -s "$SUBJECT" $
MAILTO
fi
LVL 8
LindaCAsked:
Who is Participating?
 
woolmilkporcCommented:
I mean - exchange -eq and -ne, because it seems that it should work just contrary to what you posted.
0
 
woolmilkporcCommented:
>> I want to evaluate if PARAM1 or not PARAM2 <<

shouldn't it be

if [[ $PARAM1  -eq 0 || $PARAM2  -ne 0 ]]; then ...

?

wmp
0
 
LindaCAuthor Commented:
Checking.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
LindaCAuthor Commented:
I don't know why it email me with error:

PARAM1=$(egrep -i -c "ORA-|rejected|Killed|skipped" "$log")
PARAM2=$(egrep -i -c "Server status = 0" "$log")
if [[ $PARAM1  -eq 0 || $PARAM2  -ne 0 ]]; then
    (cat $TXTERROR;uuencode $ATTFILE Coldbackup-log.txt) | mail -s "$SUBJECT" $M
AILTO
else
    (cat $TXTDEPLOY;uuencode $ATTFILE Coldbackup-log.txt) | mail -s "$SUBJECT" $
MAILTO
fi
text-deploy.txt
text-error.txt
prueba.txt
Coldbackup-log.txt
0
 
woolmilkporcCommented:
It will email you with error (the "then" branch)
 if the log does not contain ( ORA- or rejected or Killed or skipped) [because the count returned by grep is zero)
  or if the log does contain ( Server status = 0 ) [because the count returned by grep is zero]

So I think you should invert your logic ...

wmp
0
 
sjm_eeCommented:
$ cat doit
#!/bin/sh

PARAM1=$1
PARAM2=$2
if [[ $PARAM1  -eq 0 || $PARAM2  -eq 0 ]]
then
    echo "then"
else
    echo "else"
fi
$ ./doit 0 0
then
$ ./doit 1 0
then
$ ./doit 0 1
then
$ ./doit 1 1
else

Problem?
0
 
LindaCAuthor Commented:
Checking
0
 
dougaugCommented:
You can do this:

egrep -i -c "ORA-|rejected|Killed|skipped" "$log"
PARAM1=$?                                      
egrep -i -q  "Server status = 0" $log
PARAM2=$?                                      
if [[ $PARAM1  -eq 0 || $PARAM2  -ne 0 ]]; then
....

In this way you will get an error mail if any of the words ORA-|rejected|Killed|skipped appear on the log or if the phrase "Server status = 0" doesn't appear.

You will only get a deploy mail if none of the words ORA-|rejected|Killed|skipped exist and only if the string  "Server status = 0" exists in the log.
0
 
LindaCAuthor Commented:
egrep -i -c "Server status = 0" TBSPROD_COLD.2010-04-15.log  1
egrep -i -c "ORA-|rejected|Killed|skipped" TBSPROD_COLD.2010-04-15.log  0

So if [[ $PARAM1  -gt 0 || $PARAM2  -ne 1 ]]; then

because -c I think it means count ?
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.

All Courses

From novice to tech pro — start learning today.