Solved

crontab  and perl script

Posted on 2003-11-11
4
1,059 Views
Last Modified: 2008-02-26
I have a perl script that runs totally fine if I login as its owner but when I set it up to run in cron tab, it fails.
It seems ENVIRONMENT VARIABLES is different when cron runs the script.
.profile does not run when scripts runs in crontab.
I am not sure if this is a unix question or perl question but anyway I am posting it here.

here is my perl script although I don't think is needed. In .profile there is one a line that runs another file and I explicitly included in the code but still does not work.(`. /usr/oracle/OPROD/8.1.7/OPROD.env`)

#!/usr/perl5/bin/perl

sub trim {
 my $string = shift(@_);
 $string =~ s/\s//g;
 return $string;
};
`. /usr/oracle/OPROD/8.1.7/OPROD.env`;
$MO=`date +%m`;
$DAY=`date +%e`;
$YR=`date +%Y`;
$HH=`date +%HH`;
$date="$MO-$DAY-$YR-$HH";
$date=trim($date);
$cmd="/usr/oracle/OPROD/8.1.7/bin/exp userid=system/dont*know owner=hrsys compress=y";
$cmd = "$cmd log=exp_hrsys.log file=/apsun02/usr1/home/hrsys/exp_hrsys_$date";
`$cmd`;
0
Comment
Question by:prokni
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
arjanh earned 50 total points
ID: 9725072
The following should work instead of the last line:

`. /usr/oracle/OPROD/8.1.7/OPROD.env; $cmd`;
0
 
LVL 2

Author Comment

by:prokni
ID: 9725116
Then for each command that I want to run I have to setup my environment variables right befroe running the command!
is there any way to compile .profile in the beginnig of teh code and run other commands after that.
0
 
LVL 5

Expert Comment

by:arjanh
ID: 9725169
Nope. A child shell process is started with the default settings (so without loading the profile) for each command between backticks. So consecutive commands each get a fresh shell, without a history of previously executed commands.
0
 
LVL 2

Author Comment

by:prokni
ID: 9725202
Great info. Really really appreciated it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question