Home » Infrastructure » Unix » Script works individially but not when put in cron
Script works individially but not when put in cron [message #272469] Fri, 05 October 2007 03:12 Go to next message
raj75
Messages: 11
Registered: August 2007
Junior Member
Hi ALL,

I 'm trying to perform a export of metadata and modeldata of my application on the Oracle DB written by another DBA,the script works fine when run but when put in cron it fails. Kindly help. Thanks

My Script

#!/bin/ksh
#
rm -f /tmp/metadata/temp.txt
cd /tmp/metadata/data
rm -f *
cd /tmp/metadata/log
rm -f *

$ORACLE_HOME/bin/sqlplus -s dedb/xxx > /tmp/metadata/temp.txt<<EOFarch1
set heading off
set pagesize 0
set linesize 2048
set feedback off
select table_name from user_tables;
exit;
EOFarch1

for df in `/bin/cat /tmp/metadata/temp.txt`
do
exp dedb/xxx FILE=/tmp/metadata/data/$df.dmp LOG=/tmp/metadata/log/$df.log ROWS=N GRANTS=Y CONSTRAINTS=Y TRIGGERS=Y TABLES=$df
done
Re: Script works individially but not when put in cron [message #272473 is a reply to message #272469] Fri, 05 October 2007 03:22 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
In cron ".profile" is not sourced, you have to set all environment variables in your script.

Regards
Michel
Re: Script works individially but not when put in cron [message #272478 is a reply to message #272469] Fri, 05 October 2007 03:52 Go to previous messageGo to next message
raj75
Messages: 11
Registered: August 2007
Junior Member
Michel thanks,

I tried adding into the script the variables as below but still in cron the script cannot do the job.

#!/bin/ksh
#
_=/usr/bin/env
PATH=/usr/bin:/usr/ucb:/etc:/usr/ccs/bin:/usr/openwin/bin:/opt/oracle/product/9.2.0/bin:.
EDITOR=vi
SHELL=/usr/local/bin/ksh
MAIL=/var/mail/oracle
HOME=/opt/oracle
ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/product/9.2.0
TERM=dtterm
LOGNAME=oracle
rm -f /tmp/metadata/temp.txt
cd /tmp/metadata/data
rm -f *
cd /tmp/metadata/log
rm -f *
$ORACLE_HOME/bin/sqlplus -s dedb/xxx > /tmp/metadata/temp.txt<<EOFarch1
set heading off
set pagesize 0
set linesize 2048
set feedback off
select table_name from user_tables;
exit;
EOFarch1

for df in `/bin/cat /tmp/metadata/temp.txt`
do
exp dedb/xxx FILE=/tmp/metadata/data/$df.dmp LOG=/tmp/metadata/log/$df.log ROWS=N GRANTS=Y CONSTRAINTS=Y TRIGGERS=Y TABLES=$df
done

Pls assist.
Re: Script works individially but not when put in cron [message #272491 is a reply to message #272478] Fri, 05 October 2007 04:38 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
the script cannot do the job

Are you sure this sentence gives sufficient information for us to help you?

Regards
Michel
Re: Script works individially but not when put in cron [message #272498 is a reply to message #272478] Fri, 05 October 2007 04:54 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You didn't export your variables.
You have to set AND export them.

Regards
Michel
Re: Script works individially but not when put in cron [message #272555 is a reply to message #272498] Fri, 05 October 2007 09:05 Go to previous messageGo to next message
Ronald Beck
Messages: 121
Registered: February 2003
Senior Member
Take your original script

#!/bin/ksh
#
rm -f /tmp/metadata/temp.txt
cd /tmp/metadata/data
rm -f *
cd /tmp/metadata/log
rm -f *

$ORACLE_HOME/bin/sqlplus -s dedb/xxx > /tmp/metadata/temp.txt<<EOFarch1
set heading off
set pagesize 0
set linesize 2048
set feedback off
select table_name from user_tables; 
exit;
EOFarch1

for df in `/bin/cat /tmp/metadata/temp.txt`
do
exp dedb/xxx FILE=/tmp/metadata/data/$df.dmp LOG=/tmp/metadata/log/$df.log ROWS=N GRANTS=Y CONSTRAINTS=Y TRIGGERS=Y TABLES=$df
done


and replace $ORACLE_HOME with /opt/oracle/product/9.2.0 and see if your script will run properly. If it does, you then need to learn the proper syntax for assigning environment variables in ksh.

Ron
Re: Script works individially but not when put in cron [message #273013 is a reply to message #272555] Mon, 08 October 2007 11:48 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Simply soure your profile (or preferably a bare bones profile - don't just blindly include and export everything) in cron:
15,45 * * * * . .my_profile; myscript.sh
Previous Topic: Compressing a File with Time stamp in Unis Shell Script
Next Topic: ps -ef|grep command question
Goto Forum:
  


Current Time: Sun Dec 04 18:40:41 CST 2016

Total time taken to generate the page: 0.07059 seconds