8 |
|
|
9 |
use strict; |
use strict; |
10 |
use vars qw($Msgno); |
use vars qw($Msgno); |
11 |
|
use SAP::Rfc; |
12 |
use Digest::MD5 qw(md5_hex); |
use Digest::MD5 qw(md5_hex); |
13 |
use MIME::Parser; |
use MIME::Parser; |
14 |
use SAP::Rfc; |
use XML::Simple; |
15 |
|
use Data::Dumper; |
16 |
|
|
17 |
# configuration |
# read configuration from xml file |
18 |
|
my $config = XMLin(); |
19 |
|
|
20 |
# directory in which attachemnts will be left |
# directory in which attachemnts will be left |
21 |
my $outdir = "/var/autofs/data/export_sigma"; |
my $outdir = $config->{outdir} || die "config: on <outdir> defined"; |
22 |
# temporary directory (ON SAME FILESYSTEM AS $outdir -- we use rename!) |
# temporary directory (ON SAME FILESYSTEM AS $outdir -- we use rename!) |
23 |
# for extraction of *ALL* attachements |
# for extraction of *ALL* attachements |
24 |
my $msgdir = "/var/autofs/data/export_sigma/mime$$"; # temp |
my $msgdir = $config->{msgdir} || die "config: no <msgdir> defined"; |
25 |
my $log = "/data/sap_sigma/orders.log"; |
$msgdir .= "$$"; # append PID to make it unique |
26 |
|
my $log = $config->{log} || die "config: no <log> defined"; |
27 |
|
|
28 |
|
# open log and redirect die to it... |
29 |
|
open(LOG,">> $log") || warn "open log $log: $!"; |
30 |
|
local $SIG{__DIE__} = sub { print LOG $_[0] ; die $_[0] }; |
31 |
|
|
32 |
|
# init SAP rfc |
33 |
|
# |
34 |
my $rfc = new SAP::Rfc( |
my $rfc = new SAP::Rfc( |
35 |
ASHOST => 'cipkg', |
ASHOST => $config->{sap}->{ashost}, |
36 |
USER => 'rfctest', |
USER => $config->{sap}->{user}, |
37 |
PASSWD => 'dinamo', |
PASSWD => $config->{sap}->{passwd}, |
38 |
LANG => 'HR', |
LANG => $config->{sap}->{lang}, |
39 |
CLIENT => '200', |
CLIENT => $config->{sap}->{client}, |
40 |
SYSNR => '20', |
SYSNR => $config->{sap}->{sysnr}, |
41 |
TRACE => '0' |
TRACE => $config->{sap}->{trace} |
42 |
) || die "new: $!"; |
) || die "new: $!"; |
43 |
|
|
|
my $it = $rfc->discover("Z_ZDMM0123_SIGMA_RFC") || die "discover: $!"; |
|
|
|
|
|
$it->FILEPATH( "ZSIGMA" ); |
|
|
$it->PORT( "ZIDOC" ); |
|
44 |
|
|
45 |
# no user editable content beyond this point |
# no user editable content beyond this point |
46 |
|
|
47 |
umask 022; # world readable |
umask 022; # world readable |
48 |
|
|
49 |
open(LOG,">> $log") || warn "log $log: $!"; |
$rfc->is_connected || die "SAP rfc: not connected"; |
|
|
|
|
$rfc->is_connected || die "not connected"; |
|
50 |
|
|
51 |
#------------------------------------------------------------ |
#------------------------------------------------------------ |
52 |
# dump_entity - dump an entity's file info |
# dump_entity - dump an entity's file info |
71 |
$new=~s/ +/_/g; |
$new=~s/ +/_/g; |
72 |
$new=~s/^.*\/([^\/]+)$/$1/g; |
$new=~s/^.*\/([^\/]+)$/$1/g; |
73 |
$new=~s/[^a-zA-Z._0-9]//g; |
$new=~s/[^a-zA-Z._0-9]//g; |
74 |
|
|
75 |
|
# never try to overwrite file |
76 |
|
my $suffix = ""; |
77 |
|
while (-e "$outdir/$new$suffix") { $suffix++; } |
78 |
|
$new .= $suffix; |
79 |
|
|
80 |
rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!"; |
rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!"; |
81 |
print LOG scalar localtime," $new\n"; |
print LOG scalar localtime," $new\n"; |
82 |
|
|
83 |
# now, call SAP rfc |
# now, call SAP rfc |
84 |
|
|
85 |
$it->FILENAME( "$new" ); |
my $it = $rfc->discover("Z_ZDMM0123_SIGMA_RFC") || die "discover: $!"; |
86 |
|
|
87 |
|
$it->FILEPATH( "ZSIGMA" ); |
88 |
|
$it->FILENAME( $new ); |
89 |
|
$it->PORT( "ZIDOC" ); |
90 |
|
|
91 |
$rfc->callrfc( $it ); |
$rfc->callrfc( $it ); |
92 |
} |
} |
93 |
} |
} |