Software

Question

Help understand Perl script(s)

Hi,

need some help to understand what this Perl script do. The guy who made it is probably dead since it's so old, but we need it.

Can u guys help? :)

I've censored stuff.
If someone could remake this script over to another language used today, that would be great.
Thread display: Collapse - | Expand +

All Answers

Collapse -

First file:

by Perlsomewhat In reply to Help understand Perl scri ...

## .bat file:

@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

Collapse -

2nd file .pl

by Perlsomewhat In reply to Help understand Perl scri ...

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";

Collapse -

3d file .load

by Perlsomewhat In reply to Help understand Perl scri ...

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;

Collapse -

1st file .bat

by Perlsomewhat In reply to Help understand Perl scri ...

@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

Related Discussions

Related Forums