Site icon EasyOraDBA

Shell Script to Keep Oracle Always Free Autonomous Database Alive with SQLCL

After searching on the internet long and hard I couldn’t find a quick shell script to access Oracle Autonomous Database using SQLCL. This is important for me to keep my Always Free DB Instances alive. If you do not make a HTTPS or SQL*NET connection to your Autonomous Always free DB then it shuts down in 7 days and in 90 continuous days of inactivity it is deleted.

The same does not apply to the Always Free Linux instances, so what I did was downloaded the Instance wallets onto my Always Free OL7 instance and put this shell script in crontab to run every 3hrs to ensure my instances are never shutdown. This is a simple hack/solution and here it goes

  1. Download Instance Autonomous Wallet onto your Linux Instance
  2. Download and Install SQLCL
  3. Save this Script as a shell script file ‘Load_ADB.sh’
#!/bin/bash
username='admin'
password='YourP@ssw0rd$#'
password2='YourP@ssw0rd33$#'
sqlquery='select sysdate from dual;'
/home/opc/sqlcl/bin/sql /nolog <<-EOF
set cloudconfig /home/opc/Wallet_primepay.zip
show tns
connect $username/$password@primepay_high
$sqlquery
EOF
/home/opc/sqlcl/bin/sql /nolog <<-EOF
set cloudconfig /home/opc/Wallet_Online.zip
show tns
connect $username/$password2@online_high
$sqlquery
EOF

4. Schedule it in crontab

* */3 * * * bash /home/opc/Load_ADB.sh >> /tmp/adbquery.log

That’s it a simple hack to keep your Always Free ADB Instances alive indefinetly 🙂

Exit mobile version