LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem in executing script through crontab (https://www.linuxquestions.org/questions/linux-newbie-8/problem-in-executing-script-through-crontab-4175533141/)

suicidaleggroll 02-08-2015 08:26 AM

The @ goes at the beginning of the line...

I thought you wrote this script? Are you even looking at the errors you're seeing?

azheruddin 02-08-2015 11:07 AM

can anyone assist here/

azheruddin 02-09-2015 01:27 AM

Hi suicidaleggroll,
Can you please have a look error, changes been done in script as suggested.

anon04 02-09-2015 03:23 AM

KISS
 
It's a rough sketch, but maybe this will be of some help.
Not sure if it will work so please test safely. :D

There are three files to modify/create:
(1) /etc/crontab
(2) /home/oracle/my_cron_script.bash
(3) /home/oracle/my_cron.sql
(4) /home/oracle/my_cron_script.log

The fourth is a log file produced by the my_cron_script.bash

-unimatrixdoc

#########################################
# FILENAME: /etc/crontab
#########################################
Code:

# Man page for crontab:
# http://ss64.com/bash/crontab.html
# recommend using a user crontab!

# replace user_name with correct user that has rights
06 0 * * * user_name bash /home/oracle/my_cron_script.bash > /home/oracle/my_cron_script.log

#########################################
# FILENAME: /home/oracle/my_cron_script.bash
#########################################
Code:

#!/bin/bash

# Basic info about the ORACLE_HOME environment varible can be found here:
# http://docs.oracle.com/cd/E11882_01/server.112/e16604/qstart.htm#i1055567
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/client_1

# Are you trying to run SILENT? it's capital -S
# http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch3.htm#i1169374
/home/oracle/app/oracle/product/11.2.0/client_1/bin/sqlplus -S /nolog < /home/oracle/my_cron.sql

# sql file syntax can be found here:
# http://ss64.com/ora/syntax-sqlplus.html

# Info about /nolog
# http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch3.htm#sthref628

#########################################
# FILENAME: /home/oracle/my_cron.sql
# NOTE: put a fullpath to
# extract_data.sql location
#########################################

Code:

CONNECT user/user_1234@CBDTEST
@extract_data.sql


MiraiKuma 10-30-2015 12:46 PM

Fix
 
I ran into this today. Using a couple of links around the internet I found the solution to be as follows:

Edit your crontab so it looks like this:

SHELL=/bin/bash
*/15 * * * * . /home/HomeFolder/.profile; cd /directory/of/your/script; ./runScript.sh > /dev null 2>&1

Please note the . before the full path to your profile. This for me worked while everything else did not. What is happening is bash does not run in an environment by default. So as you have tried and failed (as did I) you have to setup your environment variables manually. I could not get mine to work right either with sqlplus so I used this. It declares that you run all cronjobs in a bash environment, it sources your .profile, changes the directory to the directory of your script, then runs your script.

You may not need to cd like I did. I have some other scripts that need to be called from the same directory. Can't hurt anything by using the cd command.

Hope this helps.


All times are GMT -5. The time now is 03:40 AM.