Solved

crontab  and perl script

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

831 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