LindaC
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|skip ped" "$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
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|skip
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
ASKER
Checking.
ASKER
I don't know why it email me with error:
PARAM1=$(egrep -i -c "ORA-|rejected|Killed|skip ped" "$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
PARAM1=$(egrep -i -c "ORA-|rejected|Killed|skip
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$ 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?
#!/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?
ASKER
Checking
You can do this:
egrep -i -c "ORA-|rejected|Killed|skip ped" "$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|skipp ed 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|skipp ed exist and only if the string "Server status = 0" exists in the log.
egrep -i -c "ORA-|rejected|Killed|skip
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|skipp
You will only get a deploy mail if none of the words ORA-|rejected|Killed|skipp
ASKER
egrep -i -c "Server status = 0" TBSPROD_COLD.2010-04-15.lo g 1
egrep -i -c "ORA-|rejected|Killed|skip ped" TBSPROD_COLD.2010-04-15.lo g 0
So if [[ $PARAM1 -gt 0 || $PARAM2 -ne 1 ]]; then
because -c I think it means count ?
egrep -i -c "ORA-|rejected|Killed|skip
So if [[ $PARAM1 -gt 0 || $PARAM2 -ne 1 ]]; then
because -c I think it means count ?
shouldn't it be
if [[ $PARAM1 -eq 0 || $PARAM2 -ne 0 ]]; then ...
?
wmp