Crontab strange behaviour

Hi all,

I'm having this scenario which for the moment I cannot resolve. :frowning:

I wrote a script to make a dump/export of the oracle database. and then put this entry on crontab to be executed daily for example.
The script is like below:

cat /home/oracle/scripts/db_backup.sh 
#!/bin/ksh 
 
#Backup export database script 
#Created 05-04-2011 
# * * * 
 
DATE=`date +%d%m%Y-%H%M%S` 
ARCHIVE_DIR=/home/oracle/arch 
SCRIPTS_DIR=/home/oracle/scripts 
USER=oracle 
PASS=XXXXXXXX 
 
( 
echo "Starting database dump ..." 
date 
 
cd $ARCHIVE_DIR 
exp $USER/$PASS FILE=filename_$DATE.dmp log=logfile_$DATE.log 
 
echo "End of database dump ..." 
date 
 
) | tee $ARCHIVE_DIR/exp_logfile-$DATE.log 2>&1

Also the crontab entry:

host> crontab -l 
00 11 * * * /home/oracle/scripts/db_backup.sh 2>&1

The crontab entry and also the script is executed as oracle user. When I execute directly from the shell the script is executed correctly and the dump is also generated ok.
But on the cron job I get only the log part "Starting/Stoping database dump ..." and not the export dump file and dump_log file: the "exp..." part. :confused:

What can be the problem?

Thanks

Enid

The error messages will be in unix mail for the owner of the cron.

The default environment for cron is very limited. Any extra environment which has been set for whichever interactive user ran the script successfully needs to be put into the script if you want it to work from cron.

In your case I doubt if "exp" is in $PATH and also there are no ORA environment variables set.

Try running "set" from the command line and compare with the output of a one-off cron containing just "set".

Hi methyl,

Thanks for your reply,
indeed the problem was related to the environment variables :wink:
running

set

on the two occasions, shell and cron gave different env variables.
So I added at the beginning of the script this part:

. /home/oracle/.profile

Everything OK , the dump export and the dump_log is created ok :), but strange because the scripts stops/exits after the exp command and I don't get the last echo and date part of the script.

It is a minor problem , but I'll try to figure out why it stops there.

Regards

no very clear