Hey I have this shell script that I am trying to run and receive a value from a sql query.Then later use the value in an if stmt... I cannot get this to work for nothing..
Here is the script
(sqlplus -s $usrname/$passwrd <<!
set head off feed off pagesize 0
select b
from table;
set head on feed on pagesize 55
!
) | read b
echo $b
if [ "$b" = "off" ];
then
echo "Bin $msg!"
else
echo "Bin off $msg!"
fi
Hey I have this shell script that I am trying to run and receive a value from a sql query.Then later use the value in an if stmt... I cannot get this to work for nothing..
Here is the script
(sqlplus -s $usrname/$passwrd <<!
set head off feed off pagesize 0
select b
from table;
set head on feed on pagesize 55
!
) | read b
echo $b
if [ "$b" = "off" ];
then
echo "Bin $msg!"
else
echo "Bin off $msg!"
fi
devaris22, please read our rules. Especially:
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.
Off hand I have two comments. One probably relates to your issue and the other is more style.
If your query returns no records then your "if" statement is going to be invalid. Enclose your $b variable with double quotes. text if [ "$b" = "on" ]
Style: You are resetting your SQL*Plus parameters at the tail end of your here document. This doesn't accomplish anything since sqlplus is exiting anyway.