Link to home
Start Free TrialLog in
Avatar of LindaC
LindaCFlag for Puerto Rico

asked on

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
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

>> I want to evaluate if PARAM1 or not PARAM2 <<

shouldn't it be

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

?

wmp
Avatar of LindaC

ASKER

Checking.
Avatar of LindaC

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$ 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?
Avatar of LindaC

ASKER

Checking
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.
Avatar of LindaC

ASKER

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 ?