Solved

crontab  and perl script

Posted on 2003-11-11
4
1,051 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
  • 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now