Cron Environment


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cron Environment
# 1  
Old 07-13-2005
Cron Environment

I am trying to run a series of perl scripts at different times using crontab under solaris. The scripts that i am using require some specific environment variables to be specified for database functionality, but i would also like it that i can specify a few global variables for output locations.

i have a .cronWrapper which is just a file that specifies additional environment variables, but how do i replace/add to the crontab environment variables with the data in the .cronWrapper file?

cron now:
* * * * * $HOME/scripts/environment.pl > cron_test_out.txt 2>&1

how i would like it to be:
* * * * * $SCRIPTS/environment.pl > $OUT_LOG 2>&1

anyone?
# 2  
Old 07-13-2005
* * * * * . /path/to/.cronWrapper && $SCRIPTS/environment.pl > $OUT_LOG 2>&1
# 3  
Old 07-13-2005
cron:
* * * * * . ./.cronWrapper && $TEST_DIR/environment.pl > $TEST_LOG 2>&1

.cronWrapper:
# define cron environment variables
ORACLE_HOME='/Oracle10g/OraHome_1';
PATH='/bin:/usr/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:/opt/sfw/bin:/usr/local/lib:/usr/lib:/usr/ucb/:/usr/ccs/bin:/usr/openwin/bin:/pt/sfw/bin:/opt
/SUNWppro/bin:/usr/sadm/bin:/Oracle10g/OraHome_1/bin';
LD_LIBRARY_PATH='/usr/dt/lib:/usr/local/lib:usr/openwin/lib:usr/lib';
CLASSPATH='.:/usr/java';

# cron variables
DAILY_LOG=$HOME'/tmp/daily.log';
CLEANUP_LOG=$HOME'/tmp/cleanup.log';
SCRIPTS=$HOME'/mailscripts';
TEST_DIR=$HOME'/scripts';
TEST_LOG=$HOME'/cron_test_out2.log';


what happens is, it creates the log file correctly in my home directory which contains:
environment variables:
HOME -> /home/ageboff
LOGNAME -> ageboff
SHELL -> /usr/bin/sh
TZ -> US/Eastern
PATH -> /bin:/usr/bin:/usr/local/bin:/opt/sfw/bin:/usr/local/lib:/usr/lib:/Oracle10g/OraHome_1/bin

done


NOTE: environment.pl is a perl script that just iterates through the environment variables and outputs the key and value

but i need the script running to see the environment variables also, not just the crontab itself
# 4  
Old 07-13-2005
Quote:
Originally Posted by Smitty McSmith
but i need the script running to see the environment variables also, not just the crontab itself
i added an export line in the .cronWrapper and it all showed up!

id add this to the cron FAQ (just a suggestion)
# 5  
Old 07-13-2005
.cronWrapper:
Code:
# define cron environment variables
ORACLE_HOME='/Oracle10g/OraHome_1';
PATH='/bin:/usr/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:/opt/sfw/bin:/usr/local/lib:/usr/lib:/usr/ucb/:/usr/ccs/bin:/usr/openwin/bin:/pt/sfw/bin:/opt
/SUNWppro/bin:/usr/sadm/bin:/Oracle10g/OraHome_1/bin';
LD_LIBRARY_PATH='/usr/dt/lib:/usr/local/lib:usr/openwin/lib:usr/lib';
CLASSPATH='.:/usr/java';
export ORACLE_HOME PATH LD_LIBRARY_PATH CLASSPATH

# cron variables
DAILY_LOG=$HOME'/tmp/daily.log';
CLEANUP_LOG=$HOME'/tmp/cleanup.log';
SCRIPTS=$HOME'/mailscripts';
TEST_DIR=$HOME'/scripts';
TEST_LOG=$HOME'/cron_test_out2.log';
export DAILY_LOG CLEANUP_LOG SCRIPTS TEST_DIR TEST_LOG

# 6  
Old 07-13-2005
great minds...
# 7  
Old 07-13-2005
is it possible to not have the
* * * * * . ./.cronWrapper && <BLAH>
on every line? and just have it at the head of the file and have it apply to the rest of the cron?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

My active tickets will not be available in the cron environment

Hi everybody , when I run a script from the command line it works but returns a failure if I run it from crontab. Basically I wanted to send a file to hdfs, I thought it was related to the fact that crontab do not know the path to hdfs so I put the full path but it still does not work: here... (1 Reply)
Discussion started by: beautymind
1 Replies

2. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

3. 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

4. Shell Programming and Scripting

Run script through cron with user environment variables

Hi everyone, I wrote a script that is supposed to be run by cron on a daily basis. It works just fine if I run it manually, but due to a lack of environment variables (which are available during my user session but not when cron runs the script) it keeps failing to run successfully. Here's the... (2 Replies)
Discussion started by: gacanepa
2 Replies

5. Shell Programming and Scripting

Cron not inherting the environment in solaris 2.5.1

Solaris 2.5.1 I have written a shell script that creates a tar file and then ftp's the file to an other box. The shell script perfectly executes when run manually through terminal. But when i schedule it through cron, its not executing and showing exit code RC =1 in cron log. I have added the... (3 Replies)
Discussion started by: venu
3 Replies

6. Solaris

Environment variables and cron

where do you set environment variables for cron jobs? I have a feeling it would ignore ~/.bashrc ? thanks. (2 Replies)
Discussion started by: orange47
2 Replies

7. Shell Programming and Scripting

Setting environment variables in Cron file

Hi, In Cron file i'm using username and password hard-coded and now i wann to use environmental veraiables in cron file. But Could you please guide me how to use these environmental variables in cron file ? Thanks, Shyamu.A (4 Replies)
Discussion started by: shyamu544
4 Replies

8. AIX

AIX and cron logs filtering ?: /etc/cronlog.conf, /var/adm/cron/log

Hi, I can use 'crontabs –e' and do all the scheduling I like. However I would like to auto send myself just the cronjobs logs that fail. That is to say the PIDs that fail and the related lines with those PID’s only. (Not the full set of logs) Has anyone done this work? Or does an AIX 5.3 tool... (0 Replies)
Discussion started by: Keith Johnson
0 Replies

9. UNIX for Advanced & Expert Users

Reset environment - ".. /etc/.environment dev_env"

I have been resently working on some ksh script. One of the line in the file writes: .. /etc/.environment dev_env I can not understand what this mean, all I know is .environment is unix system environment file. Is ".." a command? If some one can give me some clue where can I find information... (7 Replies)
Discussion started by: zzwu3591
7 Replies

10. Solaris

Setting environment variables within cron jobs!!

Is it possible to use environment variables within cron jobs. I am using a cron job to run a c program at regular intervals. The C program uses a library and i have set the library path in the LD_LIBRARY_PATH environment variable. But when i ran the job i got the error library not found!! Any... (1 Reply)
Discussion started by: atheek
1 Replies
Login or Register to Ask a Question