I have a shell script which select total count from a table and use its value in a if condition like below
connect_string="username/password@tnsname"
tot=`sqlplus -s $connect_string << EOF
set echo off
set feedback off
set head off
select count(*) from test_table;
EOF
`
if [ $tot -gt 0 ]
then
echo "Value is "$tot
else
echo "No records found"
fi
On execution i get a ora error
ERROR: ORA-28002: the password will expire within x days
So my script fails saying
[: too many arguments. How to turn off ORA errors in shell script?
Ignoring errors is a terrible idea. It is a change in sqlplus you want, not shell.
connect_string="username/password@tnsname"
tot=`sqlplus -s $connect_string << EOF
set echo off
set feedback off
set head off
whenever sqlerror continue
select count(*) from test_table;
EOF
`
However your problem occurs during login, not during script execution. There is no simple way that I know to block that error. Try resetting you password for starters.
What i required is if there is any ORA or SQL error then i have assign the value as 0 to the variable tot