Operating System - HP-UX
1836607 Members
1962 Online
110102 Solutions
New Discussion

cron causes script to fail

 
Dan Baker_3
Occasional Advisor

cron causes script to fail

one of my dbas has a script that runs fine from the command line, but fails when run by cron
Here is the script:

oracle@luna:default:o cat exp.ksh
#!/usr/bin/ksh
export ORACLE_SID=EBPROD
cd /ora_backup
rm exp_EBPROD.dmp.gz
mknod node1 p
gzip < node1 > exp_EBPROD.dmp.gz &
exp / file=node1 buffer=50000000 log=/ora_backup/exp_EBPROD.log statistics=none full=y grants=none indexes=y compress=none constraints=y direct=y
rm -f pipe.file

Basically, it sets up a pipe, dumps the export to the pipe, where it is picked up by gzip and output to a file

here is the crontab entry
59 10 * * * /bin/ksh -c '. $HOME/.profile; cd /ora_backup; /ora_backup/exp.ksh;'

here is the pertinent error from Oracle:
EXP-00002: error in writing to export fileerror closing export file node1
EXP-00000: Export terminated unsuccessfully

It lloks to me like oracle is unable to write to the pipe. And yet, it is able to do so when the script is run from the command line.

Any suggestions?

Dan Baker
12 REPLIES 12
Alan Meyer_4
Respected Contributor

Re: cron causes script to fail

when the script is run from command line, the user has executed an oracle env setup which is not run when the script is run from cron.
" I may not be certified, but I am certifiable... "
Dan Baker_3
Occasional Advisor

Re: cron causes script to fail

How is that? He is running his profile in the crontab entry.
Pete Randall
Outstanding Contributor

Re: cron causes script to fail

Cron has a very limited set of environmental variables available to it. You need to make sure that any variables, including path are set explicitly in your script.


Pete

Pete
Pete Randall
Outstanding Contributor

Re: cron causes script to fail

Or use full path names for all commands.


Pete

Pete
Alan Meyer_4
Respected Contributor

Re: cron causes script to fail

the cron job does not execute the login profile for roacle when it executes the job. you need to include a line similiar to

. /home/oracle/.profile

at the beginning of the job to include the oracle environment.
" I may not be certified, but I am certifiable... "
Kent Ostby
Honored Contributor

Re: cron causes script to fail

Put a + sign in the top of the script and run some tests.

I suspect that Pete is right in that the only changes from cron to command line tend to be the environment variables.

If you have not set all the same environment variables to run or the full path names are not used, its quite possible that certain files arent being found.
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Dan Baker_3
Occasional Advisor

Re: cron causes script to fail

Well,the crontab entry clearly loads the profile, but just to make sure, I added this line to the beginning of the script:

. /oravl01/oracle/.profile

Still no dice. Anyting else?
Alan Meyer_4
Respected Contributor

Re: cron causes script to fail

I tested it some myself and retract the suggestions about the user env, but I agree with Pete about the limited amount of system environmental and path availability. Test out the script with the + like Kent said or put in some print/echo statements to check the availability of the pipe...
" I may not be certified, but I am certifiable... "
Alan Meyer_4
Respected Contributor

Re: cron causes script to fail

(cont) because the system /etc/profile does not get executed by cron
" I may not be certified, but I am certifiable... "
A. Clay Stephenson
Acclaimed Contributor

Re: cron causes script to fail

I suspect that what is wrong are the permissions on the pipe because the default mode is 666 but that is modified by umask which is not the same under cron. Add a chmod 666 node1 after the mknod. Also make sure that gzip starts by specifying a full pathname.

Sourcing oracles .profile is also problematic because it probably has commands like tset, stty, tabs ... which expect stdin to be a tty device. Surround all of those in .profile with
if [[ -t 0 ]]
then
tput ..
stty ..
fi
If it ain't broke, I can fix that.
Dan Baker_3
Occasional Advisor

Re: cron causes script to fail

either sourcing the /etc/prfile or adding the chmod command fixed the problem. Thanks, guys!
Alan Meyer_4
Respected Contributor

Re: cron causes script to fail

Hey, you might want to think of giving the other guys points too, they put in a lot of effort too...
" I may not be certified, but I am certifiable... "