connect to sqlplus from shell

I'm writting a shell script and at the begining I login to sqlplus by
sqlplus -l user_name/password@instance
what I would like is to check if the database is down or not , and if the database has started moved to the next step else sleep for a certain time and then check again .
I know how to do the sleep part, but I don't know how to check if the database is not down. can some one help me please.

Thanks,

you can check with $? status.if database is down you will not be able to connect with data base.

if [ $? != 0 ]
then
PROGRAM_STATUS=`echo NOT CONNECTED TO SQL`
fi

you may check another post here

am using infomix database on unix os

if [ `tbstat - | grep On-Line | wc -l` -eq 0 ]
then
        echo Informix database seems to be down. Please start the database
        echo do this do this
else
        echo database is running
        echo do this
fi

where tbstat is used to find database status...here you have to find out the command which gives status of your database....

For quick and "dirty" check you can use something like this:

oracheck ()
{
  printf "whenever sqlerror exit failure\nselect null from dual;\n" |
  sqlplus -sl user/pass 2>&- 1>&- || return 1
}


Usage:

until oracheck; do sleep n; done
go_to_the_next_step

If its on Informix use

 onstat -