Operating System - HP-UX
1820707 Members
2629 Online
109627 Solutions
New Discussion юеВ

Re: Why perl script always fails in crontab ?

 
cpchan
Occasional Advisor

Why perl script always fails in crontab ?

I need to run sqlplus + perl script in crontab in order to rebuild SAP index regularly.
But I don't know the script fail in crontab but success in command prompt.
Any ideal ?


10 REPLIES 10

Re: Why perl script always fails in crontab ?

maybe you must source the /etc/.profile in the script
Torsten.
Acclaimed Contributor

Re: Why perl script always fails in crontab ?

... or specify the full path to sqlplus.

Anyway, something like "it fails" only is never a good description of a situation.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Prashanth Waugh
Esteemed Contributor

Re: Why perl script always fails in crontab ?

Hi Cpchan,

Check for cron log. the path is
#/var/adm/cron/log

Regards
Atul
For success, attitude is equally as important as ability
Prashanth Waugh
Esteemed Contributor

Re: Why perl script always fails in crontab ?

hi cpchan,

pls check #crontab -l ouput and paste it here


Reagrds
Atul


For success, attitude is equally as important as ability
Steven E. Protter
Exalted Contributor

Re: Why perl script always fails in crontab ?

Shalom,

cron has no environment.

Your script needs a PATH variable set or must have all external calls include the full path.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Why perl script always fails in crontab ?

Hi:

You might be enlightened if you use the 'warnings' pragma (let alone the 'strict' pragma' in your code!

Regards!

...JRF...
Fred Ruffet
Honored Contributor

Re: Why perl script always fails in crontab ?

This kind of problem is most of the time resulting of the no environnement execution. When a program is launched from cron, profiles (/etc/profile and .profile) are not sourced, so env variables such as PATH are not loaded. Modify your program to load them or run your program through "su - user -c..." commands.

Best regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
cpchan
Occasional Advisor

Re: Why perl script always fails in crontab ?

Thanks every bodies.
I need to run this script through crontab :

#!/opt/perl/bin/perl
#
# Use SAP BR*TOOLS to reorganize indexes in SAP database
#



# save the name of index with poor storage quality into a file
$sql = "/oracle/DEV/920_64/bin/sqlplus sapdev/password \@/oracle/DEV/genrebidx2.sql";
$result = system($sql);
........
........

ORACLE_HOME fail
Case 1
export ORACLE_HOME=/oracle/DEV/920_64;

Bareword found where operator expected at /oracle/DEV/idx_rebuild.sh line 7, near "/oracle/DEV"
(Missing operator before DEV?)
syntax error at /oracle/DEV/idx_rebuild.sh line 7, near "/oracle/DEV"
Execution of /oracle/DEV/idx_rebuild.sh aborted due to compilation errors.

Case 2
$cmd="ORACLE_HOME=/oracle/DEV/920_64";
$result=system($cmd);

Error 6 initializing SQL*Plus
Message file sp1.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

Case 3
export ORACLE_HOME="/oracle/DEV/920_64";

Can't locate object method "export" via package "ORACLE_HOME" (perhaps you forgot to load "ORACLE_HOME"?) at /oracle/DEV/idx_rebuild.sh line 7.

Any ideal ?
Ralph Grothe
Honored Contributor

Re: Why perl script always fails in crontab ?

Haven't you heard about Perl's %ENV hash?
This is where you would set the environment in a Perl program.
e.g.

BEGIN {
$ENV{ORACLE_HOME} = '/app/oracle/product/10.2.0';
$ENV{ORACLE_SID} = 'Something According to your tnsnames.ora';
}

Besides, running sqlplus in a system() call
isn't the best way to talk to your Oracle.
The common way in Perl was to "use DBI;".
This of course requires that you have DBD::Oracle installed in your Perl,
which under HP-UX can admittedly be a bit tricky (or ot at least used to be in the past).
Most of all it requires a perl built with following two leading libswanted:

$ perl -V:config_args
config_args='-Duselargefiles -Duse64bitall -A prepend:libswanted=cl pthread ';

But today this is all explained very detailed in the README.hpux that accompanies the DBD-Oracle*.tar.gz which you get from CPAN.

I suggest you check if your perl build meets this requirement using above perl -V invocation or this one

$ perl -V:libswanted
libswanted='cl pthread sfio socket bind inet nsl nm ndbm gdbm db malloc dl dld sun m crypt sec util c cposix posix ucb bsd';

Remember, that "cl pthread " must be leading the list of libs otherwise you will suffer.

Then open your CPAN shell as root,
install DBI and download DBD::Oracle

# perl -MCPAN -e shell

CPAN> install DBI
.
. # lots of output
.
CPAN> get DBD::Oracle


Now to install the DBD::Oracle module you should by all means first successfully run all tests of the module,
which requires careful preparation of your environment beforehand.
That's why I didn't suggest to simply issue
"install DBD::Oracle" above, as this usually fails.
So after the download of DBD::Oracle was successful you need to switch to the shell and prepare and run the test by manual invocation.
Do a

CPAN> look DBD::Oracle

This should have given you a shell and put you in the build directory of DBD::Oracle
Now please, *do* read the POD carefully before continuing because as said it is all outlined in it.

# perldoc README

and even more important

# perldoc README.hpux

or

# perldoc README.hpux.txt

if the README's name has changed to the latter.
If you fail to start perldoc for whatever reason you can also simply load the READMEs
into your favorite pager (like more).
Don't be put off by the strange POD markup then (viz. lines starting with an equals sign in the first column)
Then follow exactly the necessary steps mentioned in the POD.
After having installed DBD::Oracle successfully go on to read the PODs of
DBD::Oracle (mainly the section on how to connect) and DBI (for all the rest).



Madness, thy name is system administration
cpchan
Occasional Advisor

Re: Why perl script always fails in crontab ?

Yes, thanks a lot.
I just fixed my problem with :

#!/opt/perl/bin/perl
#
# Use SAP BR*TOOLS to reorganize indexes in SAP database
#
#

$ENV{"ORACLE_HOME"}="/oracle/DEV/920_64";
$ENV{"ORACLE_SID"}="DEV";
$ENV{"PATH"}="/oracle/DEV/920_64/bin:/sapmnt/DEV/exe";

It works.
But there were other errors occurred.
SAP errors.
I will fix them by searching some SAP sites.
Thank you very much.