Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

crontab Perl scrip

mmdallal
Valued Contributor

crontab Perl scrip

Hello,

how can I run a perl script from crontab?

BR
6 REPLIES
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