1745864 Members
4496 Online
108723 Solutions
New Discussion юеВ

Re: crontab Perl scrip

 
mmdallal
Valued Contributor

crontab Perl scrip

Hello,

how can I run a perl script from crontab?

BR
6 REPLIES 6
mmdallal
Valued Contributor

Re: crontab Perl scrip

OS is RHEL 4.8
Vitaly Karasik_1
Honored Contributor

Re: crontab Perl scrip

exactly as you do this from your command line.
just be sure you have full path to perl binary in your command or in the first line of your script.
mmdallal
Valued Contributor

Re: crontab Perl scrip

Hi Vitaly,

in cron:

* * * * * /u01/app/oracle/product/10.2.0/db_1/perl/bin/perl /usr/OVPI/connect.pl >>& /usr/OVPI/test_perl.txt

does not write any in the file /usr/OVPI/test_perl.txt

but when I run it in the shell it is OK

BR
Ralph Grothe
Honored Contributor

Re: crontab Perl scrip

Maybe merely a typo, the position of the ampersand?
Do you realy mean to background the connect.pl command?
Or did you just want to redirect both stdout and stderr to test_perl.txt?
Then I think it would have to be

* * * * * /u01/app/oracle/product/10.2.0/db_1/perl/bin/perl /usr/OVPI/connect.pl &>>/usr/OVPI/test_perl.txt

But check with man bash in the section REDIRECTIONS if this abbreviated syntax is valid.
Madness, thy name is system administration
Vitaly Karasik_1
Honored Contributor

Re: crontab Perl scrip

please check email of crontab's owner - you should see the error.

and AFAIK it should be

/u01/app/oracle/product/10.2.0/db_1/perl/bin/perl /usr/OVPI/connect.pl >> /usr/OVPI/test_perl.txt
mmdallal
Valued Contributor

Re: crontab Perl scrip

hello,

the problem is resolved when I fixed the Oracle home environment variables in the perl script, as follow:
------------
BEGIN {
unless ($ENV{ORACLE_PERL}) {
$ENV{ORACLE_HOME} = "/u01/app/oracle/product/10.2.0/db_1";
$ENV{ORACLE_PERL} = "$ENV{ORACLE_HOME}/perl";
$ENV{PERL5LIB} = "$ENV{PERL5LIB}:$ENV{ORACLE_PERL}/lib:$ENV{ORACLE_PERL}/lib/site_perl";
$ENV{LD_LIBRARY_PATH} = "$ENV{LD_LIBRARY_PATH}:$ENV{ORACLE_HOME}/lib32:$ENV{ORACLE_HOME}/lib";
exec "$ENV{ORACLE_PERL}/bin/perl", $0, @ARGV;
}
}

------------

Thank you all