crontab and shell script that executes a sql.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting crontab and shell script that executes a sql.
# 1  
Old 06-06-2005
crontab and shell script that executes a sql.

Problem:
I have a crontab and when it kicks off, xxx.sh shell script is called. Which has a nohup sqlplus session call. Problem is sql does not get executed and a text file is not getting created. Only a empty log file is getting created. Are there any constraints for crontab to open a sql plus session? Why is the sql not spooling the data? If I execute this shell script on command line every thing works nicely.

I have a crontab that is calling a shell script:
28 14 * * 1-5 $HOME/xxx.sh >> $HOME/xxx.log

code in xxx.sh:
nohup sqlplus userid/password@host @${SCRIPTSD}/xxx.sql ${OUTPUTD}/outfile.txt $datamonth > ${SCRIPTSD}/xxx.log &

wait
exit 0

Only the xxx.log file is getting created. No data file is getting created!
Does anybody know what's the problem.

ThankYou,
Radhika.
# 2  
Old 06-06-2005
Radhika, please read the FAQs and search before posting.

This is most likely because the environment is not set up to run the commands in your script from cron.

the user in this thread had the same problem. This tread was a direct link from the cron and crontab faq.
# 3  
Old 06-06-2005
2 suggestions:

1. redirect stderr to a file, to see what happens.
28 14 * * 1-5 $HOME/xxx.sh >> $HOME/xxx.log 2>>error.log

2. add relative environments for sqlplus in xxx.sh.
# 4  
Old 06-06-2005
I am sourcing the file by putting the following command in the shell script:

. .profile

It still doesn't work. I am going to try the trace on and see what happens.

Thanks,
Radhika.
# 5  
Old 06-07-2005
Quote:
Originally Posted by radhika
I am sourcing the file by putting the following command in the shell script:

. .profile

It still doesn't work. I am going to try the trace on and see what happens.

Thanks,
Radhika.
What shell is the the users login shell? It it is a csh or tcsh user then .profile will not be the one used to set up the user environment.
# 6  
Old 06-07-2005
It is kshell.
# 7  
Old 06-07-2005
It worked! I was sourcing the wrong profile file- the one with application variables and not the generic one with environment set up information. I guess it IS! time to call it a day.

ThankYou! all for your suggestions.
Radhika.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh: How to write the log file simultaneously when .sql file executes by UNIX process

Hello Team- we would like to implement an approach which has to write the log file simultaneously when .sql file is executing by Unix process. At present,it is writing the log file once the process is completed. I've tested the current process with the below approaches and none of them... (1 Reply)
Discussion started by: Hima_B
1 Replies

2. Shell Programming and Scripting

Will shell script executes in sequence

I have a shell script scheduled in cron job to run at every 1 minute which transfers files to remote machine and then move the files to backup folder. cd /u01/app/ftp_tmp sftp user@hostname <<-EOF cd /home/user/ftp mput * bye EOF mv /u01/app/ftp_tmp/* /u01/app/ftp_bkp Now the problem is... (6 Replies)
Discussion started by: Bhavi
6 Replies

3. UNIX for Dummies Questions & Answers

Crontab + Script + .sql

Hi guys today i'll bring to you a new problem that i need to execute. So what i need to do it's create a script that: conect to some database logon run a .sql script logoff and close the connection after that, put this script on the crontab To set up the crontab it's ok for me, i think... (3 Replies)
Discussion started by: Newer
3 Replies

4. Shell Programming and Scripting

Shell script not getting called through cron job but executes fine manually.

Hi, My shell script not getting called through cron job. The same works fine when executed manually. I tried to generate logs to find if the scripts has some errors related to path using following command- trying to execute .sh file every 5 mins: */5 * * * * /home/myfolder/abc.sh... (17 Replies)
Discussion started by: Dejavu20
17 Replies

5. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

6. Shell Programming and Scripting

Running a script in crontab which executes a jar file

Hi, I have a script (.sh file) which has been created through my login. This script executes a jar file. Java is installed through my login and the folder has been given full permission for access. When this script is added by root in crontab, it does not get executed. Could you please... (1 Reply)
Discussion started by: archana.n
1 Replies

7. UNIX for Dummies Questions & Answers

crontab entry executes sporadically

I have a crontab entry that goes out to 12 servers each day and gathers statistics about their dayend processing. The script goes to both HP and AIX servers (which shouldn't make a difference, I don't think). We output the job to a log file. Some weeks, the job will run successfully every day... (2 Replies)
Discussion started by: kweikel
2 Replies

8. Shell Programming and Scripting

script not working from crontab, executes individual

Hi, This script is working successfully when i executed from shell prompt, but the same script scheduled in crontab its not deleting the files, #! /bin/bash DAY_1=`(date --date='4 months ago' '+%Y-%m')` log=/tmp/cleant adir=/u01/app/oracle/admin/talon/adump... (4 Replies)
Discussion started by: saha
4 Replies

9. Shell Programming and Scripting

shell script executes program, but waits for a prompt

Sorry, newbie here. I have the following shell script which basically executes the sh-n-body.i686 program a specified number of times. However, before the sh-n-body.i686 begins its calculations it prompts for input from the user. In this case the user would have press ". return" and... (7 Replies)
Discussion started by: lionatucla
7 Replies

10. Shell Programming and Scripting

Calling SQL LDR and SQL plus scripts in a shell script

Hi- I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment... I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert... (5 Replies)
Discussion started by: rajagavini
5 Replies
Login or Register to Ask a Question