Running SQLPLUS Script in CRONTAB


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Running SQLPLUS Script in CRONTAB

Hi,
Can someone please help me here with this one.

This is my script:
Code:
# more tosh.sh
#!/usr/bin/ksh
clear
. /home/oracle/.profile
echo "Good morning, world."
export ORACLE_HOME=/u01/app/oracle/product/9.0.1
export PATH=$ORACLE_HOME/bin:/usr/local/bin
export ORACLE_SID=xxxx

/u01/app/oracle/product/9.0.1/bin/sqlplus -s xxxx/xxxx @/home/ivbbuild/rec.sql > /home/ivbbuild/rech.txt

However when I run it from crontab I dont get anything. What am I missing here.

My CRONATAB entry:
Code:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/ivbbuild/tosh.sh > /home/ivbbuild/tile.txt 2>&1

The tile.txt file is produced with just "Good morning, world.". The file with SQL output is not produced (/home/ivbbuild/rech.txt)
Tosh.

Moderator's Comments:
Mod Comment Use code tags please, ty.

Last edited by zaxxon; 06-15-2010 at 02:22 AM.. Reason: code tags
# 2  
Hi Tosh,

Have you terminated the SQL statement inside '/home/ivbbuild/rec.sql' with semi colon?

Also exit is expected inside the SQL file when you do it in this fashion. Refer below example

Code:
$ cat 1.sh
sqlplus -s username/passwd @1.sql > 1.txt
$ cat 1.sql
select * from dual;
exit
$ sh 1.sh
$ cat 1.txt

D
-
X

$

# 3  
Maybe something is missing in the environment? Missing another variable you need to export?
You could also try to add a 2>&1 in the end of the sqlplus line, just in case to catch everything.

Is the SQL statement running fine when being run on the command line? If yes, then maybe I'd go for a missing environment variable.
# 4  
Hi ranjithpr/Zaxxon,

Here is my .sql file:
Code:
$ more rec.sql
select sum (balancechange)
from thistory INNER JOIN account ON 
accounthistory.subscriberid = account.subscriberid 
where ((account.msisdn not like'200%') 
and (account.msisdn not like '100%')) 
and changedate between to_date(SYSDATE) and to_date(SYSDATE + 1)
and UPDATEMETHODID in ('334');
exit;

Also where do I add 2>&1 in the .sql file (before the semi colon or not)?

Thanks in advance guys.

Tosh.
# 5  
Zaxxon mean in 'sqlplus' line, not in sql file. You have to add it like

Code:
/u01/app/oracle/product/9.0.1/bin/sqlplus -s xxxx/xxxx @/home/ivbbuild/rec.sql  > /home/ivbbuild/rech.txt 2>&1

# 6  
Hi Ranjithpr,

Will the exit clause in the .sql file have a semi colon? Please advise.
# 7  
It is not required, but if you give it won't create any problem.

In command line, are you able to execute script '/home/ivbbuild/tosh.sh', Are you getting the expected result?

Above cron tab entry is under which user, is it under 'oracle' or 'root'?
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #1
Difficulty: Medium
The UNIX and Linux Forums (UNIX.com) was founded in 1985.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

CRONTAB - one python script is not running

Hi! I'm using a RaspberryPi with standard Raspbian. Currently I'm working on some sort of weather station. For now I have three python scripts - one which is updating txt files for website - update1m.py ( it will not be necessary in few next days so I'll delete it) , second one for updating... (4 Replies)
Discussion started by: bartocham
4 Replies

2. Solaris

Script problem when running on crontab

Hi guys! I created a backup script that works fine when I run manually, but when I put a crontab job to execute it the result are not the expected. (not a time problem). Here is my script: bash-3.00# cat /bk_tool/backup2.sh #!/usr/bin/csh clear set DIR_HOST='SCP08' ... (3 Replies)
Discussion started by: andredemartini
3 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. UNIX for Dummies Questions & Answers

crontab not running script

Hi All, I am having the below script to be run from crontab, it it doesnt run. 1 * * * * /home/cobr_ext/test.sh > /home/cobr_ext/temp.txt when i run i manally it runs without any issues. Could please help me as to why doesnt it run the script.:( (7 Replies)
Discussion started by: abhi_123
7 Replies

5. UNIX for Advanced & Expert Users

Particular script not running through crontab

Hi, I have created the below script, set -x # Set the Path of Environment file ENV_FILE_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/bin LOG_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/log export ENV_FILE_DIR export LOG_DIR # Set Audit Environment . ${ENV_FILE_DIR}/QDM.env... (8 Replies)
Discussion started by: yohasini
8 Replies

6. Shell Programming and Scripting

Crontab not running a script

Hi, I posted this in the Solaris forum but I think this one would be more appropriate. I created a script starting with the following lines: #!/usr/bin/ksh flag=n export flag typeset -i quant=0 (...) When running it I'm getting the following 2 errors: /tmp/tstscript/testfail.ksh:... (9 Replies)
Discussion started by: Cvg
9 Replies

7. Shell Programming and Scripting

Problem with crontab running a script

I am trying to use the CRON utility in Fedora 11 & CentOS... I intend to run a script which pops up a warning message every hour and i made the following entry using "CRONTAB -e " * * * * * sh /bin/myscript.sh But this does not seem to be running. Another thing to note is that,... (4 Replies)
Discussion started by: Vabiosis
4 Replies

8. UNIX for Dummies Questions & Answers

Getting error when running script through crontab

Hi all, I wrote small script for Solaris and when I am running it through command prompt its ok, but when I trying to run it using crontab, i am getting error like: ld.so.1: dbloader: fatal: libACE.so: open failed: No such file or directory /tmp/file.sh: line 5: 8304 Killed ... (4 Replies)
Discussion started by: nypreH
4 Replies

9. Shell Programming and Scripting

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

cron job not running the sqlplus command in shell script but the shell script works fine from command line.. Cronjob: 5 * * * * /home/dreg/script.sh script.sh: #!/bin/ksh /oracle/u000/app/oracle/product/10204/GEN/bin/sqlplus -s <user>/<pass>@<sid/home/dreg/sqlscript.sh ... (18 Replies)
Discussion started by: Ikea
18 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

Featured Tech Videos