Hello all,
I have a perl script that accesses Sybase Database. It
works fine if I manually run it, but when I set up a
cronjob to run the script, I got the following error. I suspect this has to do with env, but i just dont
know how fix it? Could you please help. Thank you.
Well i will take a stab since no one else has replied. We had an issue where we were using XML::Simple which in turn uses the expat c lib, everything worked fine at a normal user shell but under cron we were getting a similar error. Is it possible you need to explicitly set the LD_LIBRARY_PATH or something similar that is normally part of teh default environment for the sybase DBD module. In other words are there sybase c libs or something that it uses and need to be linked in? You can specify this on the command line in the crontab before the actual command (at least on Solaris, check man for crontab).
HTH,
http://danconia.org
********* The error messages from crontab *****
Open Client Message: Message number: LAYER = (5) ORIGIN = (3) SEVERITY = (5) NUMBER = (131) Message String: ct_init(): network packet layer: internal net library error: Attempt to load protocol driver failed install_driver(Sybase) failed: DBD::Sybase initialize: ct_init(12500) failed at /usr/local/lib/perl5/5.8.0/sun4-solaris/DynaLoader.p m line 249. Compilation failed in require at (eval 1) line 3.
*********** Below is the sybdule.pm ********
#!/usr/bin/perl -w # sybmodule.pm
$sybase_dir = '/sybase/'; $scriptdir = "/sybase/dba/scripts/"; unless (-e $scriptdir){mkdir $scriptdir or die &errormsg("$0","cannot creat dir $!\n","warning");} $user = 'sa_operator'; $pswd = qx(egrep SAOPERPASSWD $sybase_dir/.sysspec | cut -d= -f2); chomp($pswd); $chao = &greeting; sub SetSybEnv{ # set sybase environment BEGIN{$ENV{SYBASE} = "/sybase"}; } sub sybase_connect{ ########################################### # Connect to Sybase Server ###########################################
my $server = $_[0]; my $usedb = $_[1]; my $sql = $_[2]; my $dbh= DBI->connect("dbi:Sybase:server=$server","$user","$pswd") or die $dbh->errstr; # or die &errormsg("$0","Cannot connect $server","Fatal"); $dbh->do("use $usedb"); $sth = $dbh->prepare($sql) || die &errormsg("$0","Cannot prepare $sql", "Warning\n$!\n"); #$sth->execute || die print "$sql\n$!\n"; $sth->execute || die &errormsg("$0","Cannot execute $sql", "Warning\n$!\n"); }
************* below is the perl script ************ #!/bin/perl -w # This script bcp out 7 important system tables of the #master db of all active servers. # Author: Loan Tran # Date: Jun 18, 2001
use DBI; use sybmodule; #BEGIN{$ENV{'SYBASE'}="/sybase";} &setsybenv; select (STDOUT); $| = 1; # make unbuffered
$systbldir = "/sybase/dba/scripts/systbl"; unless (-e $systbldir){ mkdir $systbldir or die "cannot make $systbldir $!"; } @allserver = &ListProDevTestServer;
foreach my $eachserver(@allserver){
&bcp_systables($eachserver);
}#end foreach sub bcp_systables{ my $server = $_[0]; @systables = qw(sysservers sysdatabases sysdevices sysusages syslogins sysusers sysremotelogins); #print scalar(@systables) ;
foreach $n(@systables){
print "\n bcp out $realserver..$n \n";
qx(bcp master..$n out
$systbldir/$realserver..$n.bcp -c -S$server -U$user -P$pswd);
}#end foreach
} #end sub bcp_systables
#my question here is how could i check if sub #bcp_systables run successfully before i call sub #notify?
¬ify; sub notify{ my $mailprog = "/bin/mailx"; my $from = "[EMAIL PROTECTED]"; my $to = qq([EMAIL PROTECTED] [EMAIL PROTECTED]); my $subject = ' bcp complete! ' ; open (MAIL,qq(|$mailprog -r $from -s "$subject" $to) ); print MAIL " Work completed on $date \n"; close MAIL; }#end sub
****** below is my env ********
HOME=/home/ltran
PATH=.:/home/ltran/pl:/:/bin:/usr/sbin:/usr/local/bin:/usr/local/lib/perl5:/usr/local:/usr/lib:/usr/ucb:/usr/bin:/usr/openwin/bin:/usr/hosts:/usr/xpg4/bin/:/sybase:/sybase/ASE-12_5:/sybase/OCS-12_5/bin
LOGNAME=ltran
SHELL=/bin/csh SYBASE=/sybase
SYBASE_ASE=ASE-12_5
SYBASE_OCS=OCS-12_5
EDITOR=/bin/vi
__________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]