Shell script to restart all database instances in rolling fashion

[oracle@node1 ~]$ . oraenv
ORACLE_SID = [oracle] ? +ASM1
ORACLE_BASE environment variable is not being set since this
information is not available for the current user ID oracle.
You can set ORACLE_BASE manually if it is required.
Resetting ORACLE_BASE to its previous value or ORACLE_HOME
The Oracle base has been set to /u01/app/12.1.0/grid
[oracle@node1 ~]$ srvctl config database
racdb

[oracle@node1 ~]$ for i in `srvctl config database`
> do
> for j in `srvctl status database -d $i |awk '{print $2}'`
> do
> srvctl status instance -i $j -d $i
> srvctl stop instance -i $j -d $i -f
> srvctl start instance -i $j -d $i
> srvctl status instance -i $j -d $i
> done
> done
Instance racdb1 is running on node node1

Instance racdb1 is running on node node1
Instance racdb2 is running on node node2
Instance racdb2 is running on node node2
[oracle@node1 ~]$