How to call a shellhaving sql script from cronjob


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to call a shellhaving sql script from cronjob
# 1  
Old 06-24-2008
PHP How to call a shellhaving sql script from cronjob

Hi All,
Am having a shell script JDE_REPORT_GEN.sh which intern calls a sql script JDE_CHANGED_DATA.sql. the problem here is when i run this script from the $prompt it is running fine and giving out the spool file required.

if i schedule the same shell in cronjob am not getting the spool file.Please advice this is very urgent and the content of the script is as below.
#################################
$cat JDE_REPORT_GEN.sh
#!/bin/sh

cd /tmp/azum

ORACLE_HOME=/asera/app/oracle/product/10.2.0/db_1
export ORACLE_HOME

sqlplus manta/manta@MTACS3 <<VITMAN @/tmp/azum/JDE_CHANGED_DATA.sql
exit
VITMAN
#######################################
$ cat JDE_CHANGED_DATA.sql
set echo off pagesize 49000 head off feed off veri off trimspool on
set linesize 30000
spool /tmp/azum/JDE_DATA_CHG_QTY_DUMMY_REPORT.csv

*****sql query here******

spool off;

##########################################


a prompt response to this is much appriciated.

thanks in agvance,
Azum.
# 2  
Old 07-09-2008
Quote:
Originally Posted by azum
Hi All,
Am having a shell script JDE_REPORT_GEN.sh which intern calls a sql script JDE_CHANGED_DATA.sql. the problem here is when i run this script from the $prompt it is running fine and giving out the spool file required.

if i schedule the same shell in cronjob am not getting the spool file.Please advice this is very urgent and the content of the script is as below.
#################################
$cat JDE_REPORT_GEN.sh
#!/bin/sh

cd /tmp/azum

ORACLE_HOME=/asera/app/oracle/product/10.2.0/db_1
export ORACLE_HOME

sqlplus manta/manta@MTACS3 <<VITMAN @/tmp/azum/JDE_CHANGED_DATA.sql
exit
VITMAN
#######################################
$ cat JDE_CHANGED_DATA.sql
set echo off pagesize 49000 head off feed off veri off trimspool on
set linesize 30000
spool /tmp/azum/JDE_DATA_CHG_QTY_DUMMY_REPORT.csv

*****sql query here******

spool off;

##########################################


a prompt response to this is much appriciated.

thanks in agvance,
Azum.
Write the error into a file while scheduling in cron as urscript.sh 2>error.txt
And check what the error is. Most probably it will be the some env variable not set. Then you need to set the variable in ur script.
# 3  
Old 07-10-2008
Thanks sudhamacs,
I wrotre the o/p of the shell to afile but the file got generated with no data in it. please help me further,

Regards,
azum.
# 4  
Old 07-10-2008
cron only offers a limited environment. It doesn't mimic your profile. Meaning it probably doesn't know where the sqlplus command is. Doesn't know where JDE_REPORT_GEN.sh is, or I suppose it's possible you don't have the execute bit set on your script.

Along with sudhamacs suggestion, it would be a good idea to fully qualify any commands (this is a good security practice). So your cron command would be:

/bin/sh /full/path/to/script/JDE_REPORT_GEN.sh > /tmp/myoutput 2>&1

It would also be a good idea to create the /tmp/azum directory in your script.

Code:
if [ ! -d /tmp/azum ]
then
  mkdir -p /tmp/azum
  if [ $? -ne 0 ]
  then
    echo "ERROR: Cannot create spool directory"
    exit 1
  fi
fi

And maybe output a minimal amount of tracking to ensure your script is being called at all. Myabe:

echo "Starting at `date`"

And something else at the bottom. Also, end your script with:

exit 0
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to call sql file

hi , the below script contains sql query and after executed it sends the output of the query (output.txt) to an email body with conditional subject line based on the output of all_counts_match.txt. i want to make this script generic so that it can accept the sql file as parameter and can... (5 Replies)
Discussion started by: itzkashi
5 Replies

2. Shell Programming and Scripting

How to call SQL Loader in shell script?

HI Experts, I am pretty new to scripting and i need to create a perl or shell script which should fetch a file from local directory and insert the data into a table using sql loader. This will be later added to chron job to run daily and fetch all files and load them into the table. Also i... (1 Reply)
Discussion started by: sam1234
1 Replies

3. UNIX for Dummies Questions & Answers

Call sql script

I want to call the sql query from UNIX..but how to set page size and other necessary parameters i don't know plz guide me how to do this (2 Replies)
Discussion started by: sagar_1986
2 Replies

4. UNIX for Advanced & Expert Users

call sql through shell script

Hi i am not able to connect sqlplus my script is as follows $ORACLE_HOME/bin/sqlplus << ! > /tmp/extract/DM.txt and output is SQL*Plus: Release 11.1.0.7.0 - Production on Wed Jan 18 02:53:54 2012 Copyright (c) 1982, 2008, Oracle. All rights reserved. Enter user-name: t175481... (1 Reply)
Discussion started by: tushar_spatil
1 Replies

5. Shell Programming and Scripting

call shell script from pl/sql block

Hi Experts, I want to call script_name.ksh as many time as id in customer table and also pass it as a parameter to script. someting Like below. for i in select id from customer do ./script_name.ksh $i & done I have figured out how to have ID from customer but now how to call... (3 Replies)
Discussion started by: Opamps123
3 Replies

6. Shell Programming and Scripting

how to call shell script from pl/sql loop

Hello, I am doing a shell script which contain a pl/sql loop to search for 3 values, i would like to call another shell script inside this sql loop each time it find the values. so how can i call shell script from pl/sql using its variables, any idea? Here is idea about the code: my... (1 Reply)
Discussion started by: rosalinda
1 Replies

7. Shell Programming and Scripting

how can i call a shell script from pl/sql

I would like to call the shell script from pl/sql and i need to uses the value returned by the shell script in pl/sql procedure. can any one suggest me how can i do that? (3 Replies)
Discussion started by: rajesh.P
3 Replies

8. UNIX for Dummies Questions & Answers

how can a call shell script from pl/sql

I like to call a shell script from pl/sql proceduere and i have to use the shell script return value in that procedure. i am using oracle 9i and cygwin. can any one suggest me how can i do this (0 Replies)
Discussion started by: rajesh.P
0 Replies

9. Shell Programming and Scripting

how can I call a pl/sql funciton in unix script

who can show me how to call pl/sql function or precudure in unix script.. cheers, (6 Replies)
Discussion started by: YoYo
6 Replies

10. Shell Programming and Scripting

How to call pl/sql in unix script

sample code as following: test_sql(){ #test#echo test_sql str=`$ORACLE_BIN/sqlplus -s $user/$passwd <<EOM set verify off set heading off set feedback off #--------start pl/sql { DECLARE CURSOR pah_cs IS select id from table where letter = 'abcd';... (6 Replies)
Discussion started by: YoYo
6 Replies
Login or Register to Ask a Question