Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1523
  • Last Modified:

cron job for export

I have this script to export a schema.  I can run it from command line ./exportschema.sh and everything runs fine.
When i put it into a cron job, it gets only as far as  deleting the /stage/backup/student.log file but does not generate the .dmp file.
What is missing to make this script run from cron?



!/bin/ksh
ORACLE_SID=db_01
export ORACLE_SID
                                                                                                                                                     
# Remove current  .dmp file
rm /stage/backup/export/student.dmp
rm /stage/backup/export/student.log
DIRECTORY='datapump_dir'
DUMPFILE='student.dmp'
LOGFILE='student.log'
ORACLE_ID='student/graduate'
/u01/app/oracle/product/10.1.0/db_1/bin/expdp $ORACLE_ID DIRECTORY=$DIRECTORY DUMPFILE=$DUMPFILE LOGFILE=$LOGFILE
~
0
xoxomos
Asked:
xoxomos
3 Solutions
 
JeanaMCommented:
When you run from cron you need to ensure that you have all your normal environment variables, for example, $ORACLE_HOME, $ORACLE_SID, etc.  I have a special profile that I execute in all my cron jobs so I don't have to duplicate it in every job.  Did you capture the error message in a log file?
0
 
KongCommented:
Add this to your script (make sure your .profile doesn't prompt for responses):

!/bin/ksh
. $HOME/.profile
ORACLE_SID=db_01
export ORACLE_SID
                                                                                                                                                     
# Remove current  .dmp file
rm /stage/backup/export/student.dmp
rm /stage/backup/export/student.log
DIRECTORY='datapump_dir'
DUMPFILE='student.dmp'
LOGFILE='student.log'
ORACLE_ID='student/graduate'
/u01/app/oracle/product/10.1.0/db_1/bin/expdp $ORACLE_ID DIRECTORY=$DIRECTORY DUMPFILE=$DUMPFILE LOGFILE=$LOGFILE
~
0
 
Mehul ShahIT consultantCommented:
You need to have all oracle env variables setup in the export script also. As when you execute the script mannually the env variables are setup for you when you logon to the server. This happens because whenever you login a .profile script is executed from your HOME folder. You can just copy paste all the oracle related variables from your .profile script to your export scripts and it will execute without any problems.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
JeanaMCommented:
Yes, that agrees with the method I use.  If you think that you might have more than one cron job in the future, like sqlplus scripts that monitor disk space, etc., then you might want to put all the environment variables for that database in a separate file.  You must execute it in the main script with a dot in front of the path, or else it won't work.  For example, if it is called cronprof.dbname and it as in the /home/oracle/ directory, then type  . ./home/oracle/cronprof.dbname to run it.  Since all your variables are in one script, you don't need to duplicate it, and if something changes, you only have to change it in one place.
0
 
JeanaMCommented:
Whoops, the line broke in the middle of my statement.  Here is a correction. You must to type a dot (.) then a space, then the filename with the path in front.  In this example:
. /home/oracle/cronprof.dbname
0
 
xoxomosAuthor Commented:
Thanks,  I try getting all that in sometime today.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now