0
/oracle/GR1/121/bin/sqlplus / as sysdba <<EOF >> $LOGFILE
whenever sqlerror exit sql.sqlcode;
set echo on;
set serveroutput on;
STARTUP;
EXIT
EOF

Already tried it with the path, but it hasn't worked.

7
  • What is in the $LOGFILE? DO you get any mail from this cron run? Feb 20, 2020 at 12:56
  • $LOGFILE is just the path to my logfile. This is just a part of my script.
    – plattio
    Feb 20, 2020 at 12:57
  • What is inside this log? Feb 20, 2020 at 12:58
  • Things like: ---------------------------------- START ORACLE DB AND SERVICES --------------------------------------- Oracle Database is starting on GR1 on 20.02.20 at 13:24 --------------------------------------- CHECK DATABASE STATE --------------------------------------- Check if database is online with Brconnect and R3trans... ERROR: Database is offline. Database has to be online. (Brconnect)
    – plattio
    Feb 20, 2020 at 13:00
  • 1
    can u confirm whether the cron job is scheduled for oracle user?
    – Siva
    Feb 20, 2020 at 13:23

2 Answers 2

2

To run successfully in cron such job you need to set some variables like ORACLE_SID, ORACLE_HOME and so on. The samples way to do this is to make your script on this way:

source ~/.bashrc #or .bash_profile
/oracle/GR1/121/bin/sqlplus / as sysdba <<EOF >> $LOGFILE
whenever sqlerror exit sql.sqlcode;
set echo on;
set serveroutput on;
STARTUP;
EXIT
EOF

The source command will get the variables from your login and add them to the environment where you exec this task.

1
  • 1
    Thank you so much, Romeo! It work's fine!
    – plattio
    Feb 20, 2020 at 13:35
0

You have to set related env variables in the cron file before running the cron.

Run env or export, search for oracle relevant variables and copy them into the cronfile.

Additionally read the docs ;)

1
  • Can you give me an example?
    – plattio
    Feb 20, 2020 at 13:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .