URGENT: cron job not running the sqlplus command in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting URGENT: cron job not running the sqlplus command in shell script
# 15  
Old 04-09-2009
Code:
5 * * * * . ~/.profile && /home/dreg/script.sh

# 16  
Old 04-09-2009
that's what i'm telling you, Ikea....

the .profile is NOT SOURCED IN DURING CRON.

you must explicitly do so within a shell, within your cron command.

try putting everything into another script like this:

quirks_new_script.sh:

Code:
. /home/user/.profile
/home/dreg/script.sh

vger's recommendation will only work if there are no "sh" incompatible commands within the .profile.
* edit * -- in fact, on my machine, cron does not interpret ~ correctly.

What I'm saying is this:

cron is run under the Bourne shell.
Your script is who-knows-which shell.

Therefore, you must create something that sets up the environment explicitly for your ORACLE script to run.
Do not assume ANYTHING is set up.
Remember: the user's .profile IS NOT USED THROUGH cron.

Last edited by quirkasaurus; 04-09-2009 at 04:48 PM..
This User Gave Thanks to quirkasaurus For This Post:
# 17  
Old 04-09-2009
check your environment

If a script executes from the command line but has issues in cron, it is possible that your environment is not getting set properly. With Oracle in particular, you need : ORACLE_SID, ORACLE_HOME set in your environment and ORACLE_HOME/bin must be concatenated to your path. This may be done for you by sourcing "oraenv" which typically resides in /usr/local/bin (check with your DBA). If you look in your .profile, it may contain the necessary steps to establish your environment. You can add these environment settings to your script, or you can source a separate file to set them.

an example. If your database SID is "prod1" and Oracle Home is /u01/app/oracle/product/10.2.0 then add the following to your Korne or Bourne shell:

ORACLE_SID=prod1
export ORACLE_SID
ORACLE_HOME=/u01/app/oracle/product/10.2.0
export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin
export PATH

that should get you started.
# 18  
Old 04-09-2009
It worked.

Thanks a lot lot Smilie appreciate it.
# 19  
Old 04-09-2009
I will give points to quirkasaurus. Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Troubles running DB2 command in shell script via cron

Hi there, Now I'm facing error regarding running shell script via cron. The shell script which is required to get value from database. Below is the main part of shell script. #/bin/bash #connect to database(1) db2 connect to $database user xxxx using yyyy #set values from... (3 Replies)
Discussion started by: Rohan Kishibe
3 Replies

2. UNIX for Dummies Questions & Answers

Error while running a script through cron job

Hi Team, When i am running the below query manually it is giving me the right output i.e. export PATH=/usr/sbin:/usr/bin:/sbin:/bin:$PATH ADMIN=abc@abc.com CPU_HIGH=`sar|awk '{print $9}'|sort -n|head -5|sed -n 5p` CPU_MAX=`echo "scale=3; 100-$CPU_HIGH" | bc` CPU_LOW=`sar|awk '{print... (13 Replies)
Discussion started by: Ekamjot
13 Replies

3. Solaris

Error during running sqlplus command from shell script in Solaris

I am using following code to connect to oracle database from solaris shell script. which will try thrice to connect the database ...at the 4rth atempt it will exir=t. count=0 while ; do sqlplus -s $usrname/$password@dbSID <<-EOF | tee $logfile WHENEVER OSERROR EXIT 9; WHENEVER SQLERROR... (4 Replies)
Discussion started by: millan
4 Replies

4. Solaris

cannot execute sqlplus in shell script under cron

Hi, I have a bourne shell script that needs to login into sqlplus and execute a stored procedure. I need this shell script to be run under a user crontab. It works fine if run under normal shell prompt. But it gave error message in my log file when run under crontab: SQL*Plus: Release... (4 Replies)
Discussion started by: joe_x
4 Replies

5. Shell Programming and Scripting

Running script file using cron job every 5 second

Hi All, I beginner in unix, i have no idea how to set the script file using cron job every 5 second. I also want to execute automatically the output to text file.This is my script name countsys.sh and my textfile abc.txt. (6 Replies)
Discussion started by: mastercar
6 Replies

6. Shell Programming and Scripting

Cron job shell script..

Hey Guys, i was trying out a shell script which has to remove a file for every 90 mins. this is the code i came up with . $ crontab -e file1 file1 contains 30 1 * * * * rm -r /folder1/folder2/somefile.txt Now i need the cron to run for every 90 mins. the problem with this is... (8 Replies)
Discussion started by: Irishboy24
8 Replies

7. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

8. Shell Programming and Scripting

Cron job giving error while running SSH command

Hi All, The script which i am using to SSH to remote server is working fine when i run is using ./ but when cron runs it it gives error that "ssh: not found" please help!!! (3 Replies)
Discussion started by: visingha
3 Replies

9. SuSE

inconsistent ls command display at the command prompt & running as a cron job

Sir, I using the following commands in a file (part of a bigger script): #!/bin/bash cd /opt/oracle/bin ls -lt | tail -1 | awk '{print $6}' >> /tmp/ramb.out If I run this from the command prompt the result is: 2007-05-16 if I run it as a cron job then... (5 Replies)
Discussion started by: rajranibl
5 Replies

10. Shell Programming and Scripting

running shell script from sqlplus

I have a script which connects to different database servers using sqlplus. Is there a way by which I can run a shell command on that host from sqlplus? I know about 'host' command but it runs script on the local machine where the original script is running. Is there a way to run command on the... (9 Replies)
Discussion started by: dkr123
9 Replies
Login or Register to Ask a Question