Cron Job and Environement Variables


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cron Job and Environement Variables
# 1  
Old 12-10-2008
Cron Job and Environement Variables

Hello all,
One more Cron job Query!!

Ok I have a cron job which calls a shell script.The shell scripts uses 11 parameters whose values are set up in a config file and this file is sourced using the . $custom_path/filename format in my shell script.

Now the problem is the shell script executes fine when run alone but does'nt, when run as a cron job.I have found out from this forum that, it may be because cron is not able to translate the $custom_path environement variables values.Hence I tried using the absolute path and the cron job runs fine....

Now I don't want to use the absolute path, but prefer to use the environement variable.Is there anyway it could be done?

I found a thread which talks about creating an env_profile,but could'nt understand much of it....Please help

Thanks
V
# 2  
Old 12-10-2008
you can intialize the variable in ".profile" file of your user directory .

eg:
export custom_path="<absolute path>"

Once this line is added to profile ,
Schedule you script in cron like below .

<time settings> .profile ; <script_name>

Now, cron can access $custom_path from your profile.
# 3  
Old 12-10-2008
Why don't you source the file, where the custom_path is set, in your script?

Regards
# 4  
Old 12-11-2008
Hi Franklin,
Sorry could'nt follow what you said..But I will explain my problem again.

there is a custom top(path) set for customizations of Oracle applications in the Unix box.It is called as $XXINT_TOP.This already points to a directory structure such as a/b/c/d/.

Now I have a shell script which takes 11 parameters.This script needs to be run as a cron job.Hence I have set up the cron job,but don't want to expose the parameter values(some are username and Pwds) inside the cron job.

Hence what I do is I have a config file which contains these 11 parameters with their values and I have placed the config file and the shell script which is to be run as a cron job under the $XXINT_TOP/bin folder.I source the config file inside my shell script and the shell script works fine when run alone(it takes the parameter values from the config file).

However the cron job does not run, because in the crontab i have given the cron entry as below:
*/2 * * * 1-5 sh $XXINT_TOP/bin/RCUK_FILES_TRANSFER.ksh >>/a1/b1/c1/cron_log 2>&1

The cronlog file has this error:
/bin/RCUK_FILES_TRANSFER.ksh: /bin/RCUK_FILES_TRANSFER.ksh: No such file or directory

I think this is because the cron is not able to translate the value for the $XXINT_TOP environment variable.

How do I get around this problem.

Thanks
V
# 5  
Old 12-11-2008
You can run the script with the full path in your cron job or are there reasons not to do that?

Regards
# 6  
Old 12-11-2008
Well yes,If I do that it works fine,but I don't really like it.

You know this cron job will be propagated across various environements and each time it is done I don't want the admin to update the cron job with the absolute path(manual entry updates may lead to errors).The path $XXINT_TOP/bin will be present across all environements and referring to it eliminates the need to maintain the program .....
# 7  
Old 12-11-2008
It is possible to add the path of your script to the PATH variable in your cron file, or is that problematical too?

Regards
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unset environement variable

Hi, I have the following line in the script unset _SET_ENV_AA unset _SETENV but where I can check the value for this environement variable (2 Replies)
Discussion started by: stew
2 Replies

2. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

3. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

4. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

5. Shell Programming and Scripting

CRON Job

Hi all, Pretty new to CRON but have been messing with Ubuntu for a while now Here is the situation/problem I have run into you. I currently run a very basic back procedure by executing a daily CRON job which copies all data from one directory to a USB drive & date stamps the copy:- cp... (2 Replies)
Discussion started by: 2scoops
2 Replies

6. UNIX for Advanced & Expert Users

cron job

Hello, Can anyone help me how to set any script as cron job. I have gone through all threads but not able to get the details. Appreciate your help. I need to set test.pl to run on every Tuesday by 6am in the morning. I do not the cron file which is defined. Please help me out. ... (3 Replies)
Discussion started by: jam_prasanna
3 Replies

7. Shell Programming and Scripting

cron job

hi, i have set a cron job to run build in one of the env. it shud basically stop the server,deploy the code and start the server. while starting the server the logs are getting created with the cron account id and not the normal user because of which the server is not coming up. can you please... (4 Replies)
Discussion started by: suryans
4 Replies

8. UNIX and Linux Applications

Help regarding a cron job

Hi, I need to write cron job, which tries to build a project. It would check out code from a repository and then will attempt to build it .The results of the build would show up on a web-page (a table with rows, one for each build, should get updated; a link to the detailed log file; color green... (3 Replies)
Discussion started by: sat411
3 Replies

9. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

10. UNIX for Dummies Questions & Answers

CRON usage for CRON job

can anybody explain the usage of CRON for adding a cron job. please provide an example also for better understanding !!! Thanks (1 Reply)
Discussion started by: skyineyes
1 Replies
Login or Register to Ask a Question