需要帮助了解Perl脚本

时间:2019-11-17 19:32:22

标签: perl

Perl,有人可以帮助我了解此脚本的作用吗? 我已经删除了所有敏感信息。以及与数据库的此类连接。

曾经做过一次的用户可能已经死了,我们在迁移项目中需要它。

先谢谢了。 :)


edl400ba.bat文件:


DOCUMENT_ROOT

edl400ba.pl文件:


@echo off
rem Script called from file_import.bat
rem Is called with default parameters
rem %1 %2 %3 %4 %5 %6
rem <filename> <db_login> <ftp_host> <ftp_user> <ftp-password> <ftp-catalog>
rem perl edl400ba.pl "%area%" %area% %ip% slf %name003% >> \temp\edl400ba.log

rem If Perl is installed below ORACLE_HOME must variable PERL5LIB be blanked
set PERL5LIB=
set PATH=C:\strawberry\perl\bin;%PATH%

perl edl400ba.pl "%area%" %2 %3 %4 %5 >> \temp\edl400ba.log

edl400ba_load文件:


use Net::FTP;

$catalog=$ARGV[0] ; # e.g. %area%
$sqluser=$ARGV[1] ; # oracle connection string; user/user@user
#$sqluser="%area%" ;
$ftp_adr=$ARGV[2] ; # ftp server, ip adress
$ftp_user=$ARGV[3];
$ftp_pwd=$ARGV[4] ;
$loggfile="$catalog/proc/ftplog.$$" ;
$programname="EDL400BA" ;

$local_dir="%area%";
$read_catalog=$katalog . "/%area%" ;

chdir $catalog . "/" . $local_dir || die "could not cwd to $katalog . "/" . $local_dir \n";

$ftp = Net::FTP->new($ftp_adr, Debug => 0) or die "Can't start ftp\n";
$ftp->login($ftp_user,$ftp_pwd) or die "Login error: $ftp_user/$ftp_pwd";

$filecount=0;
foreach $file ($ftp->ls) {
if ($file =~ /^e.*/ ) {
$ftp->get($file) or die "Can't get the file $file\n";
$filecount++;
$cmd = "perl $catalog/script/load_edl400ba.pl $catalog $sqluser $file";
if ( system($cmd) == 0 ) {
$ftp->delete($file) or print "Couldn't delete the file: $file\n";
}
else {die "Error loading file: $file - ending.\n"};
rename $catalog . "/" . $local_dir . "/" . $file, $read_catalog . "/" . $file;
}
}

$ftp->quit || print "Error closing ftp (ignored)\n";

print "$filecount file(s) grabbed from the server $ftp_adr\n";

pdi100ba.bat


CATALOG=$1
USER=$2
FILE1=$3
GRNS_IN=$CATALOG /%area%
ORACLE_SID=egg;export $ORACLE_SID

# If the bad-file is found from f|r it shall be deleted
if test -r $CATALOG/bad/edl400ba.bad;
then rm $CATALOG/bad/edl400ba.bad;
fi;

# rows set to 64000 so that nothing is read in by accident
cd $CATALOG

sqlldr CONTROL=ctl/edl400ba.ctl, LOG=log/edl400ba, BAD=bad/edl400ba, DATA=$GRNS_IN/$FILe1, USERID=$USER, ERRORS=0,LOAD=99999, DISCARD=dsc/edl400ba ,DISCARDMAX=99999,ROWS=64000

# If the bad-filen has been created, an error message is given
if test -r $CATALOG/bad/edl400ba.bad;
then exit 9;
#else mv $GRNS_IN/$FILE1 $GRNS_OUT/$FILE1.read;
fi;

pdi100ba.pl


@echo off
rem Script called from file_import.bat
rem Is called with default parameters (common format for multiple batch files, not all are relevant)
rem   %1        %2        %3            %4        %5            %6      %7
rem <filename> <db_login> <ftp_host> <ftp_user> <ftp-password> <ftp-catalog> <rapp_p1> 

set CATALOG=\egg_price\price

rem If Perl is installed below ORACLE_HOME must variable PERL5LIB be blanked
set PERL5LIB=
set PATH=C:\strawberry\perl\bin;%PATH%

perl pdi100ba.pl "/egg_pris/pris" %2 %3 %4 %5 %6 >> \temp\pdi100ba.log

pdi100ba_load


use Net::FTP;

$catalog=$ARGV[0] ;     # e.g. /egg_price/price
$sqluser=$ARGV[1] ;     # oracle connection string; user/user@user
$ftp_adr=$ARGV[2] ; # ftp server, ip adress
$ftp_user=$ARGV[3]; 
$ftp_pwd=$ARGV[4] ;
$loggfile="$catalog/proc/ftplog.$$" ;
$programname="PDI100BA" ;

$local_dir="grns_in/readin/readout";
$read_catalog=$catalog . "/grns_in/readin/readout" ;


chdir "$catalog/$local_dir" || die "could not cwd to $catalog/$local_dir \n";

$ftp = Net::FTP->new($ftp_adr, Debug => 0) or die "Can't start ftp\n";
$ftp->login($ftp_user,$ftp_pwd) or die "Login error: $ftpuser/$ftppwd";


$filecount=0;
foreach $file ($ftp->ls) {
    if ($file =~ /^k.*/ ) {
        $ftp->get($file) or die "Can't get the file $file\n";
        $filecount++;
        $cmd = "perl $catalog/script/load_pdi100ba.pl $catalog $sqluser $file";
        if ( system($cmd) == 0 ) {
            $ftp->delete($file) or print "Couldn't delete the file: $file\n";
        }
        else {die "Error loading file: $file - ending.\n"}; 
                rename $catalog . "/" . $local_dir . "/" . $file, $read_catalog . "/" . $file;
    }
}

$ftp->quit; 

print "$filecount file(s) grabbed from the server $ftp_adr\n";

Thanks in advance. :) 

pdi200ba.bat


CATALOG=$1
USER=$2
FILE1=$3
GRNS_IN=$CATALOG/grns_in/readin/readout
ORACLE_SID=price;export $ORACLE_SID

# If the bad-file is found from f|r it shall be deleted 
if test -r $CATALOG/bad/pdi100ba.bad;
then rm $CATALOG/bad/pdi100ba.bad;
fi;

# rows set to 64000 so that nothing is read in by accident
cd $CATALOG
echo  "FILENAME constant \"$FILE1\" )"    > ctl/pdi100ba_del2
cat ctl/pdi100ba_del1 ctl/pdi100ba_del2 > ctl/pdi100ba.ctl

sqlldr CONTROL=ctl/pdi100ba.ctl, LOG=log/pdi100ba, BAD=bad/pdi100ba, DATA=$GRNS_IN/$FILE1, USERID=$USER, ERRORS=0,LOAD=99999, DISCARD=dsc/pdi100ba ,DISCARDMAX=99999,ROWS=64000

# If the bad-filen has been created, an error message is given
if test -r $CATALOG/bad/pdi100ba.bad;
then exit 9;
#else mv $GRNS_IN/$FILE1 $GRNS_OUT/$FILE1.read;
fi;

pdi200ba.pl


@echo off
rem Script called from file_import.bat
rem Is called with default parameters (common format for multiple batch files, not all are relevant)
rem   %1        %2        %3            %4        %5            %6      %7
rem <filename> <db_login> <ftp_host> <ftp_user> <ftp-password> <ftp-catalog> <rapp_p1> 

set CATALOG=\egg_price\price

rem If Perl is installed below ORACLE_HOME must variable PERL5LIB be blanked
set PERL5LIB=
set PATH=C:\strawberry\perl\bin;%PATH%

perl pdi200ba.pl "/egg_price/price" %2 %3 %4 %5 %6 >> \temp\pdi200ba.log

#pdi200ba_load


    use Net::FTP;

    $CATALOG=$ARGV[0] ;     # e.g. /egg_price/egg
    $sqluser=$ARGV[1] ;     # oracle connection string; user/user@user
    $ftp_adr=$ARGV[2] ; # ftp server, ip adress
    $ftp_user=$ARGV[3]; 
    $ftp_pwd=$ARGV[4] ;

    $loggfile="$CATALOG/proc/ftplog.$$" ;
    $programname="PDI200BA" ;

    $local_dir="grns_in/readin/readout";
    $read_CATALOG=$CATALOG . "/grns_in/readin/readout" ;


    chdir "$CATALOG/$local_dir" || die "could not cwd to $CATALOG/$local_dir\n";


    $ftp = Net::FTP->new($ftp_adr, Debug => 0) or die "Kan ikke starte ftp\n";
    $ftp->login($ftp_user,$ftp_pwd) or die "Feil ved innlogging: $ftp_user/$ftp_pwd";

    $filecount=0;
    foreach $file ($ftp->ls) {
        if ($file =~ /^a.*/ ) {
            $ftp->get($file) or die "Can't start $file\n";
            $filecount++;
            $cmd = "perl $CATALOG/script/load_pdi200ba.pl $CATALOG $sqluser $file";
            if ( system($cmd) == 0 ) {
                $ftp->delete($file) or print "Couldn't delete the file: $file\n";
            }
            else {die "Error loading file: $file - ending.\n"}; 
                    rename $CATALOG . "/" . $local_dir . "/" . $file, $read_CATALOG . "/" . $file;
        }
    }

    $ftp->quit; 

    print "$filecount file(s) grabbed from the server $ftp_adr\n";

1 个答案:

答案 0 :(得分:1)

快速概述:

您称为“ .bad”文件的文件

  1. 与ftp服务器建立连接,
  2. (使用命令ls在服务器上查找文件,
  3. 仅挑选文件名以“ e”开头的文件。 (模式/^e.*/
  4. 一个接一个地下载文件,并在文件上运行另一个名为load_edl400ba.pl的perl命令。

也许您可以更详细地了解已经知道和仍然需要了解的内容?