我编写了一个 perl 脚本 test.pl,它使用另一个文件 testing .pm 中编写的子例程。我可以手动成功运行此脚本,但是当我在 crontab 上运行相同的脚本时,出现以下错误
我已将两个文件的权限更改为执行权限并在脚本顶部使用。如何在 crontab 上成功运行脚本。
Can't locate testing.pm in @INC
"use testing"
Crontab : */2 * * * * PERL5LIB=$PERL5LIB:/home/test/testing.pm /home/test/test.pl > /home/test/test.log 2>&1
**
test.pl
#!/usr/bin/perl -w
use DBI;
use warnings;
use Time::Piece;
use HTML::Entities;
use lib '/home/test';
use testing
# Connecting to the database #
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost;mysql_socket=/var/run/mysqld/mysqld.sock","root","password", {'RaiseError' => 1});
# my $dob = '2009-04-21 00:00:00';
my $dob = '2009-04-22 00:00:00';
#my $dob = localtime->strftime('%Y-%m-%d %H:%M:%S');
print "\ndob : $dob\n";
$name="test";
$number=1;
$email="test@test.com"
$id="123";
if ($mail==0)
{
send_msg(0,$name,$number,$email,$aid);
}
if ($sms==0)
{
send_msg(1,$name,$number,$email,$id);
}
}
sub send_msg {
my ($type,$name,$number,$email,$id) = @_;
$sql7 = "select Sms,email from settings where Id='$id'";
$sth7 = $dbh->prepare($sql7);
$sth7->execute
or die "SQL Error: $DBI::errstr\n";
my ($sms,$email)=$sth7->fetchrow_array();
my $xml=testing::xml($type,$name,$number,$email,$sms,$email);
}
**