Environment variables causing cronjob to fail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Environment variables causing cronjob to fail
# 1  
Old 05-31-2006
Environment variables causing cronjob to fail

I am trying to run a script which makes use of these environment variables, hence i need to export them out.

i've posted a similar post in an oracle forum. I've posted the same qn here to get some advise on the scripting aspect.

i execute my program in an unix environment by typeing "export_file.sh myscript.pl" at the prompt.
it runs successfully. However when i set cronjob
0 2 * * * export_file.sh myscript.pl, i get a load of error messages.

my export file----------
Code:
export ORACLE_BASE=/directory1/oracle
export ORACLE_HOME=/directory1/oracle/product/9.0.1
export ORACLE_TERM=386
export LC_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=.:$PATH:$ORACLE_HOME/bin
export DBSTR='dbi:Oracle:'
export DBUSER='username/pass@abc'

--------below is my perl script-----
Code:
use DBI;use ENV;
my $dbh = DBI->connect($DBSTR, $DBUSER, '', { AutoCommit => 0 } ) 
my $sth = $dbh->prepare( "--some statement; END;" ) 
$sth->execute() 
$sth->finish();

----- The error message i got is ------
DBI connect('','username/pass@abc',...) failed: Error while trying to retrieve
text for error ORA-12154 (DBD ERROR: OCIServerAttach) at myscript.pl line 20
Can't call method "prepare" without a package or object reference at myscript.pl line 21.

#ERROR : Error while trying to retrieve text for error ORA-12154 (DBD ERROR:
OCIServerAttach).
# 2  
Old 05-31-2006
why not this

Why dont you run the script as
. .export.sh
from your .profile file. Then your current shell will have this parameters set. Or if it should be visible to all users put the variable declarations in /etc/profile file.
# 3  
Old 06-01-2006
Hi ranj@chn,

thank you for your reply. It was a silly mistake. Some of my paths were invalid. I amended the paths, and it could work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Environment Variables

1. The problem statement: What is the mesg value set for your environment? If it is on, how would you turn off your current session? How would you set it permanently? 3. The attempts at a solution : Read Unix The textbook. 3rd chapter has many things like environment variables and... (5 Replies)
Discussion started by: mahinkhan22
5 Replies

2. Shell Programming and Scripting

Awk script problem - Variables Causing Issue

can someone please explain to me what i'm doing wrong with this code: WELT=$(awk '(($1 ~ "^${caag}$") || ($2 ~ "^${caag}$"))' /tmp/Compare.TEXT) when run from the command line, it works. but it seems to be having a problem doing the comparison when variables are involved. i tested from... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. Shell Programming and Scripting

sort -t option causing code to fail need ASCII character

Hello, When I run this UNIX code without the -t option it gives me the desired results. The code keeps the record with the greatest datetime based on the key columns. I sort it first then sort it again with the -u option, that's it. I need to have a variable to specify an ASCII character... (2 Replies)
Discussion started by: script_op2a
2 Replies

4. UNIX for Dummies Questions & Answers

Environment variables

why are all environment variables represented in a fixed format regardless of the shell you use? like $HOME $PATH etc (6 Replies)
Discussion started by: sravani
6 Replies

5. Shell Programming and Scripting

The same script with extra variables seems to fail

Hey everyone, I have a problem with a certain shellscript. I have a script like this: #!/bin/sh template=$1 for values in {60,150,240,330}\ {60,150,240,330}\ {60,150,240,330}\ {60,150,240,330}; do set $values X=$1; Y=$2; Z=$3; M=$4 mkdir "X$X-Y$Y-Z$Z-M$M" cp... (2 Replies)
Discussion started by: mario8eren
2 Replies

6. Shell Programming and Scripting

using environment variables

say i define an environment variable in a particular script (upgrade.sh). my script is upgarde.sh and it calls another script try.sh. will this environment variable be accessible to try.sh also. if not how to I make environment variables global so that they can be used by any script. (2 Replies)
Discussion started by: lassimanji
2 Replies

7. Shell Programming and Scripting

environment variables

Hi, If i have a variable set and exported in my pofile file will that variable be available in all shell scripts created. Thanks, Radhika. (3 Replies)
Discussion started by: radhika03
3 Replies

8. Shell Programming and Scripting

Variables are not getting exported while running the script in cronjob

Hi All Some how, variables are not getting exported while running the script in cronjob. Variable value is coming blank. But the variables are geting the value when the same script I am running manually. Any idea why? When running the script in cron-job ==================================... (7 Replies)
Discussion started by: csaha
7 Replies

9. UNIX for Dummies Questions & Answers

help..Environment variables...

hi, 1). i would like to know what is meant by environment variables? 2). is the number of envi variables is a constant number for unix systems? 3). how to see the list of envi variables (and the values of the envi variables)in a single command? 4). if this questions were already asked... (3 Replies)
Discussion started by: sekar sundaram
3 Replies

10. UNIX for Dummies Questions & Answers

environment variables

Hi Folks, Is it possible somehow to unset all the environment variables which have been defined before in UNIX (Solaris). Thanks, Slava (3 Replies)
Discussion started by: spavlov
3 Replies
Login or Register to Ask a Question