end_ct=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF
select description from bravo_statistics
where trunc(time_stamp)=trunc(sysdate)-1
and description='END CAT';
EOF`
echo $end_ct;
echo $emtr_cnt;
if [$end_ct=="END CAT"]; then
echo "end_cat"
else
echo "value not found"
fi
then i am getting following error message :
bravo_main_refresh.sh: test: ] missing
i exactly don't know what is missing here. please present you views on this.
thanks, now atleast i am not getting white space error, but it is not actually meeting the given value.
if [ "$end_ct" = "END CAT" ]; then
echo $end_ct
else
echo "value not found"
fi
i have echo'ed the value from the select statement and it is "END CAT" only but while checking condition it is falling to the else condition rather . please suggest.
It may be working, but it is not working properly.
When comparing strings, use the = operator; when comparing numbers, use the -eq operator.
If you want the then code to run only when both conditions are TRUE, use the && operator to separate the test commands. If you want the then code to run when either or both conditions are TRUE, use the || operator to separate the test commands.
So, you need:
if [ "$end_ct" = "END CAT" ] || [ $emtr_cnt -eq 1 ]; then
or
if [ "$end_ct" = "END CAT" ] && [ $emtr_cnt -eq 1 ]; then
You said you were adding a condition, but you never said whether you require both conditions to evaluate to TRUE or if you only require one of the conditions to evaluate to TRUE.
test1 && test2 evaluates to TRUE if test1 evaluates to TRUE and test2 evaluates to TRUE. (Note that test2 won't be evaluated if test1 evaluates to FALSE.)
test1 || test2 evaluates to TRUE if test1 evaluates to TRUE or test2 evaluates to TRUE, or both evaluate to TRUE. (Note that test2 won't be evaluated if test1 evaluates to TRUE.)
So we know that $end_cnt does not expand to END CAT and we know that $emtr_cnt does not expand to a string of decimal digits.
Several posts back, I asked you to turn on tracing and show us the output. You never did that. Please help yourself and us by turning tracing on early in your script with:
set -xv
show us your complete updated script, and show us the output from the trace if it isn't obvious what is going wrong when you look at the trace output.
If you are not sure do an example longhand to get your head around it!
An example:-
#!/bin/bash --posix
# if_then.sh
end_ct="END DOG"
emtr_cnt=0
# If first is correct _OR_ second is correct...
if [ "$end_ct" == "END CAT" ] || [ $emtr_cnt -eq 1 ]
then
echo "Woohoo at least one works..."
else
echo "Neither are correct!!!"
fi
# The first result will be "Neither are correct!!!"
# Now change one or both of the two variables to a correct value and rerun!
Change one or both of the variables to the correct value and rerun...
Last login: Fri Jul 19 12:48:00 on ttys000
AMIGA:barrywalker~> ./if_then.sh
Neither are correct!!!
AMIGA:barrywalker~>
#!/bin/csh
# *** Lovely Sethi 08/2013 ***
# This process executes the BRAVO_MAIN_REFRESH.sql
#
# This file should be scheduled in CRONTAB to run each Big run.
# /uv1402/u207/home/bravodba/bestdbscript/shscriptfiles/RUNDATE.sh
end_ct=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF
select description from bravo_statistics
where trunc(time_stamp)=trunc(sysdate)-4
and description='END CAT';
EOF`
echo $end_ct;
emtr_cnt=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF
select count(*) from mrs.bill_cal
where trunc(actual_run_date)=trunc(sysdate)-3;
EOF`
echo $emtr_cnt;
if [ "$end_ct" -eq "END CAT" ] && [ $emtr_cnt -eq 1 ]; then
echo $end_ct
else
echo "value not found"
fi
#sqlplus $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID @/uv1402/u207/home/bravodba/bestdbscript/sqlscriptfiles/BRAVO_MAIN_REFRESH.sql
#/uv1402/u207/home/bravodba/bestdbscript/shscriptfiles/sendmailanalysisrefresh.sh
value of both the variables are true, so it should echo $end_ct, but instead it is first giving an error: