Solved

crontab  and perl script

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

895 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

18 Experts available now in Live!

Get 1:1 Help Now