?
Solved

crontab  and perl script

Posted on 2003-11-11
4
Medium Priority
?
1,060 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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

771 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