这是Perl脚本,它将连接到SFTP服务器并选择一些文件。此脚本在Unix服务器下的Crontab中设置。执行此脚本时,我可以看到以下错误。 请告诉我我需要做什么。
ERROR:
Can't locate Math/GMP.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Util/SSH1MP.pm line 7.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Util/SSH1MP.pm line 7.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Util.pm line 56.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Key/RSA1.pm line 6.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/SSH1.pm line 13.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/SSH1.pm line 13.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl.pm line 52.
SCRIPT:
#!/usr/local/bin/perl
use Net::SFTP;
use File::Copy;
use POSIX;
sub date_time()
{
my ($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime;
$mon = $mon+1;
$year = $year + 1900;
if (length($mon) == 1 ) { $nmon = "0$mon"; } else {$nmon = $mon; }
if (length($day) == 1 ) { $nday = "0$day"; } else {$nday = $day; }
if (length($hour)== 1 ) { $nhour = "0$hour"; }else {$nhour = $hour;}
if (length($min) == 1 ) { $nmin = "0$min"; } else {$nmin = $min; }
if (length($sec) == 1 ) { $nsec = "0$sec"; } else {$nsec = $sec; }
return "$year-$nmon-$nday $nhour:$nmin:$nsec";
}
#open(LOG,">>/scripts/cons.Log") or print " Cant open log file \n";
opendir(DIR,"/home/ftpcon/conin");
#@files=grep{/.csv$/} readdir(DIR);
@files= grep{!/^.$|^..$/} readdir(DIR);
closedir(DIR);
if ( $sftp = Net::SFTP->new("xxxxxxxxx.net.au", user => "xxxxxx" , password => "xxxxxx") )
{
#print " SFTP server connected (".date_time().") \n";
}
else
{
print "SFTP server not connected (".date_time().") \n";
}
foreach $file ( @files )
{
print " Started $file (".date_time().") \n";
my ($Psec, $Pmin, $Phour, $Pday, $Pmon, $Pyear, $Pwday, $Pyday, $Pisdst) = localtime();
$unixtime = mktime ($Psec, $Pmin, $Phour, $Pday, $Pmon, $Pyear, $Pwday, $Pyday, $Pisdst);
$Gtime = $unixtime + 25200 ;
my ($Gsec, $Gmin, $Ghour, $Gday, $Gmon, $Gyear, $Gwday, $Gyday, $Gisdst) = localtime($Gtime);
my $GTyear = 1900 + $Gyear;
if (length($Gmon) == 1 ) { $GTmon = "0$Gmon"; } else {$GTmon = $Gmon; }
if (length($Gday) == 1 ) { $GTday = "0$Gday"; } else {$GTday = $Gday; }
if (length($Ghour)== 1 ) { $GThour = "0$Ghour"; }else {$GThour = $Ghour;}
if (length($Gmin) == 1 ) { $GTmin = "0$Gmin"; } else {$GTmin = $Gmin; }
if (length($Gsec) == 1 ) { $GTsec = "0$Gsec"; } else {$GTsec = $Gsec; }
$Gdate = "$GTyear$GTmon$GTday";
$Gtime = "$GThour$GTmin$GTsec";
#($date,$time) = (split(/\_/,$file))[-2,-1];
$originalfile = (split(/\./,$file))[0];
$Gfilename = $originalfile."_".$Gdate."_".$Gtime.".csv";
$originalfilename = $originalfile.".csv";
$filetransfered = 0;
print " $file renamed as $Gfilename for Processing (".date_time().") \n";
###Connection to SFTP server
if ( $sftp->put("/home/ftpcon/conin/$file","/xxxxxxxx/yyy/$Gfilename") )
{
print " $filename Copied to SFTP Server (".date_time().")\n";
$filetransfered = 1;
}
else
{
$mailfile = "mailretrieve.txt";
open(MAIL,">$mailfile");
print MAIL " $file Not Transfered ";
close(MAIL);
$cmd = "mailx -s \"File Not Transfered to SFTP Server\" xxxx\@goxxx.com < $mailfile";
system($cmd);
unlink("$mailfile");
exit 1;
}
if ( $filetransfered )
{
$source = "/home/ftpcon/conin/$file";
$destination = "/home/ftpcon/coninbackup/$originalfilename";
$success = copy($source,$destination);
if ( $success )
{
print " 1 .$filename copied from $source to $destination (".date_time().") \n";
}
else
{
print " File Not transfered in coninbackup \n";
}
$destination2 = "/home/ftpcon/coninbak/$originalfilename";
$success = move($source,$destination2);
if ( $success )
{
print " 2.$filename moved from $source to $destination2 (".date_time().") \n";
}
else
{
print " File Not Transfered in coninbak \n";
}
print "--------------------------------------------------------\n";
}
}
#close(LOG);
exit;
#$sftp->ls("." , sub { print $_[0]->{longname}, "\n" });
答案 0 :(得分:2)
有两个问题:
Perl 5.8.8是Perl的旧版本。它于2002年发布 - 大约12年前。如果您使用的是Solaris,则可以从Sun Freeware升级到Perl 5.18。我强烈建议你这样做,因为从Perl 5.10开始,Perl开始引入许多不错的新功能并添加了更多的标准模块。例如,Perl 5.10包含Time::Piece,它将替换您在大约4个语句中显示的大部分代码。我的大多数Perl脚本现在至少需要Perl 5.10才能运行。
另一个问题是您需要安装Math::GMP
,可能还需要安装Net::SSH::Perl
。
每当您看到消息Can't locate ... in @INC
,然后是一堆包含目录perl
和site
的目录时,您就缺少必需的模块。我假设您可能需要同时安装两者,但如果您安装Math::GMP
,它可能还会安装其他相关模块,可能包括Net::SSH::Perl
(尽管我对此表示怀疑)。
您还应该考虑询问您是否可以使用Perlbrew。 Perlbrew允许您安装Perl的多个本地副本。这将允许您添加CPAN模块,而无需通过IT部门完成整个 Mother,May I?例程。但是,虽然您可以在没有IT部门祝福的情况下安装Perlbrew,但如果没有他们的批准,我就不会这样做。您不想破坏公司政策 - 尤其是涉及计算机,未经授权的软件和系统服务器修改的公司政策。
答案 1 :(得分:1)
您必须从CPAN安装perl模块Math::GMP
。
答案 2 :(得分:0)
安装Math :: GMP
像cpan Math::GMP