7 |
use SAP::Rfc; |
use SAP::Rfc; |
8 |
use Data::Dumper; |
use Data::Dumper; |
9 |
use XML::Simple; |
use XML::Simple; |
10 |
use AnyDBM_File; |
use Fcntl; # For O_RDWR |
11 |
use Fcntl; # for O_* values |
use NDBM_File; |
12 |
|
|
13 |
my $config_file; |
my $config_file; |
14 |
|
|
27 |
|
|
28 |
# open log and redirect die to it... |
# open log and redirect die to it... |
29 |
open(LOG,">> $log") || warn "open log $log: $!"; |
open(LOG,">> $log") || warn "open log $log: $!"; |
30 |
local $SIG{__DIE__} = sub { print LOG scalar localtime $_[0] ; die $_[0] }; |
local $SIG{__DIE__} = sub { print LOG scalar localtime," ",$_[0] ; die $_[0] }; |
31 |
|
|
32 |
# directory in which are files |
# directory in which are files |
33 |
my $indir = $config->{indir} || die "config: no <indir> defined"; |
my $indir = $config->{indir} || die "config: no <indir> defined"; |
36 |
my $dbm = $config->{dbm} || die "config: no <dbm> defined"; |
my $dbm = $config->{dbm} || die "config: no <dbm> defined"; |
37 |
|
|
38 |
my %dbmhash; |
my %dbmhash; |
39 |
tie %dbmhash, "AnyDBM_File", $dbm, O_RDWR || die "tie: can't tie to '$dbm': $!"; |
tie %dbmhash, "NDBM_File", $dbm, O_RDWR, 0666 || die "tie: can't tie to '$dbm': $!"; |
40 |
|
|
41 |
my $rfc = new SAP::Rfc( |
my $rfc = new SAP::Rfc( |
42 |
ASHOST => $config->{sap}->{ashost}, |
ASHOST => $config->{sap}->{ashost}, |
50 |
|
|
51 |
$rfc->is_connected || die "FATAL: SAP not connected"; |
$rfc->is_connected || die "FATAL: SAP not connected"; |
52 |
|
|
53 |
|
print STDERR "Using '$indir' as input directory...\n"; |
54 |
|
|
55 |
|
opendir(DIR, $indir) || die "can't opendir $indir: $!"; |
56 |
|
my @files = grep { !/^\./ && -f "$indir/$_" } readdir(DIR); |
57 |
|
closedir DIR; |
58 |
|
|
59 |
|
print LOG scalar localtime," Found ",$#files+1," files in directory...\n"; |
60 |
|
|
61 |
|
foreach my $file (@files) { |
62 |
|
if ($dbmhash{$file}) { |
63 |
|
print LOG scalar localtime," New file '$file', processing...\n"; |
64 |
|
$dbmhash{$file}++; |
65 |
|
} else { |
66 |
|
print STDERR scalar localtime," Skipping file '$file'\n"; |
67 |
|
} |
68 |
|
} |
69 |
|
|
70 |
|
exit 1; # fix |
71 |
|
|
72 |
my $it = $rfc->discover($config->{sap}->{discover}) || die "FATAL: SAP discover: $!"; |
my $it = $rfc->discover($config->{sap}->{discover}) || die "FATAL: SAP discover: $!"; |
73 |
|
|
74 |
foreach my $p ($config->{sap}->{params}) { |
foreach my $p ($config->{sap}->{params}) { |