1756598 Members
2732 Online
108848 Solutions
New Discussion юеВ

Cron Job

 

Cron Job

Running a Cron job with the following commands:
<>
cat fifo3 |gzip > /oracle_exports/XPS_PRD/XPS_PRD_EXPORT.dmp.gz &
exp / file = fifo3 parfile=db_export.ctl buffer=10000000 direct=y &

Running the above script by changing the directory to where the above script is avaialable with the following command:

cd /xps_prd/express/work/xps_prd/murali
db_export.sh

Script errors out with the following message:

db_export.sh[2]: exp: not found.
db_export.sh: gzip: not found.

But i am able to run a export from the same directory '/xps_prd/express/work/xps_prd/murali' manually.

Appreciate you help to resolve this.

Milan
Knowledge grows with Sharing
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor

Re: Cron Job

Hi Milan:

The cron environment is not the same as the one you have established when you execute at command line.

One common problem is a PATH variable that doesn't contain values that allow resolution of relative paths in your script. You can resolve this by using fully qualified filenames in your script or by setting the PATH (or other environmental variables) ahead of your script in the crontab entry.

In general, environmental variables can be embedded in your script as necessary, or they can be specified and exported or file-sourced in the crontab entry like:

0 1 * * * (V=x;export V;/usr/local/bin/my.sh)

0 1 * * * (. /home/my/.env /home/my/script)

...JRF...
Maureen Gunkel
Trusted Contributor

Re: Cron Job

Milan,
In your crontab entry, I would put the following:
/xps_prd/express/work/xps_prd/murali/db_export.sh
instead of just db_export.sh.
And in your db_export.sh, add the path that gzip is in to the top of the script, ie
export PATH=$PATH:/pathofgzip
Alternatively, you can call gzip with the complete path in your db_export.sh script.
Hope that this helps,
Mo
No matter where you go, there you are.
Geetam
Frequent Advisor

Re: Cron Job

The environment in which cron executes jobs is not the same as your login environment. I quote from 'man crontab':
> cron supplies a default environment for every shell, defining:
>
> HOME=user's-home-directory
> LOGNAME=user's-login-id
> PATH=/usr/bin:/usr/sbin:.
> SHELL=/usr/bin/sh
>
> Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.

Running .profile usually causes problem when it tries to query the terminal settings. It is often better to set your environment (in your case PATH) inside your script or specify the full path in front of each command that fails (in your script 'gzip' and 'exp')