Pages

Thursday, October 4, 2018

Code Example. Linux bash, sqlplus,.write log

========================
General
========================
Execute from crontab a Linux script, that call sqlplus code.

Very important to set all the environment variables in script, because in crontab they would be missing.

========================
Code
========================
run_reports_job.sh 
run_reports_job.sql
write_log.sh

ctontab task
5 1 * * * /software/oracle/oracle/scripts/run_reports_job.sh

run_reports_job.sh 
#!/bin/bash
. /software/oracle/oracle/.bash_profile
. /software/oracle/oracle/.set_profile

. /etc/sh/orash/oracle_login.sh igt

WORKDIR=/software/oracle/oracle/scripts
cd ${WORKDIR}
./write_log.sh $0
sqlplus BGD_ROBIQ_IRM_REPORTS/BGD_ROBIQ_IRM_REPORTS@igt  @run_reports_job.sql
exit 0

write_log.sh
#!/bin/bash

PROGRAM_NAME=$1
WORKDIR=/software/oracle/oracle/scripts
cd ${WORKDIR}
RUN_DATE=`date +"%Y%m%d_%H%M%S"`
DELIMITER="============================================="
BASENAME=`basename $PROGRAM_NAME`
LOG_FILE=`echo $BASENAME | sed s/.sh/.log/`

touch $LOG_FILE
echo $DELIMITER >> $LOG_FILE
echo "Running $PROGRAM_NAME at $RUN_DATE" >>  $LOG_FILE
echo $DELIMITER >> $LOG_FILE


exit 0

run_reports_job.sql 
BEGIN
 DBMS_JOB.run(642);
 commit;
END;
/
EXIT;




No comments:

Post a Comment