#!/bin/perl use Date::Calc qw (Day_of_Week Add_Delta_Days); use strict; sub LOG; my %kunden; #INI-Datei lesen open INI, ") { chomp; my $line=$_; #print "$line\n"; my ($name,$sdir,$mail,$ddir,$pdf)=split/;/,$line; $kunden{$name}->{'mail'}=$mail; $sdir = $sdir . "\\" unless ($sdir =~ /\\$/); $kunden{$name}->{'sdir'} = $sdir; $ddir = $ddir . "\\" unless ($ddir =~ /\\$/); $kunden{$name}->{'ddir'}=$ddir; if ($pdf eq "pdf") { $kunden{$name}->{'pdf'}=1; } else { $kunden{$name}->{'pdf'}=0; } } close INI; # Letzten Wochentag ermitteln my ($ss,$mi,$hh,$dd,$mo,$yy)=localtime; my ($ded, $dem, $dey); # decreased day $yy+=1900; $mo++; my $dow = Day_of_Week($yy,$mo,$dd); if ($dow==1) { # Montag # 3 Tage zurck ($dey,$dem,$ded) = Add_Delta_Days($yy,$mo,$dd,-3); } else { # 1 Tag zurck ($dey,$dem,$ded) = Add_Delta_Days($yy,$mo,$dd,-1); } $mo = '0' . $mo if ($mo < 10); $mi = '0' . $mi if ($mi < 10); $hh = '0' . $hh if ($hh < 10); $dd = '0' . $dd if ($dd < 10); $ded = '0'.$ded if ($ded< 10); $dem = '0'.$dem if ($dem< 10); my $prevweekday = "$dey.$dem.$ded"; # voriger wochentag my $prevweekday2 = "$ded.$dem.$dey"; # voriger wochentag my $stockdate = "$dey$dem$ded$dey$dem$ded"; # voriger wochentag im brsenformat #my $date = $yy.$mo.$dd; # heute: jahr monat tag my $date = "$dey$dem$ded"; my $date2 = "$dd.$mo.$yy"; # heute_ tag monat jahr ##### TAGEBUCH MAIL LOG "STACHT $hh:$mi:$ss\n"; foreach my $kunde (keys %kunden) { LOG "$kunde $prevweekday"; my $archive = $kunden{$kunde}->{'sdir'} . "$date.zip"; my $sourcefiles="*.txt"; if ($kunden{$kunde}->{'pdf'} == 1) { LOG " Wandle txt nach pdf um"; my @tarr=glob("$kunden{$kunde}->{'sdir'}mail\\*.txt"); foreach my $file (@tarr) { `txt2pdf.exe $file -pfn200 -pfs6 -ppd7`; } $sourcefiles="*.pdf"; } if (-e glob("$kunden{$kunde}->{'sdir'}mail\\$sourcefiles")) { LOG " Packe Tagebuecher nach $archive"; `fbzip.exe -a \"$archive\" \"$kunden{$kunde}->{sdir}mail\\$sourcefiles\"`; `del \"$kunden{$kunde}->{sdir}mail\\*.pdf\"`; LOG " Maile Archiv $archive nach $kunden{$kunde}->{mail}"; `clemail -to $kunden{$kunde}->{mail} -subject \"Tagebücher vom $prevweekday2 fr $kunde\" -bodyfile bodyfile.txt -attach \"$archive\" -from hotline\@icfsystems.de -smtpserver 130.35.0.141 -smtpport 25`; LOG " Loesche Archiv $archive"; `del \"$archive\"`; } else { LOG " Keine Tagebücher zum Mailen vorhanden"; } LOG " Kopiere Tagebuecher von $kunden{$kunde}->{sdir}file ==> $kunden{$kunde}->{ddir}$dey\\$dem\\$ded\\"; $sourcefiles="*.txt"; if ($kunden{$kunde}->{'pdf'} == 1) { LOG " Wandle txt nach pdf um"; my @tarr=glob("$kunden{$kunde}->{'sdir'}file\\*.txt"); foreach my $file (@tarr) { `txt2pdf.exe $file -pfn200 -pfs6 -ppd7`; } $sourcefiles="*.pdf"; } `xcopy /y $kunden{$kunde}->{sdir}file\\$sourcefiles $kunden{$kunde}->{ddir}$dey\\$dem\\$ded\\`; `del \"$kunden{$kunde}->{sdir}file\\*.pdf\"`; LOG " Kopiere 'FILE' $kunden{$kunde}->{sdir}file\\. ins 'ARCHIV' $kunden{$kunde}->{sdir}archiv\\$dey\\$dem\\$ded\\"; `xcopy /e /c /i /y \"$kunden{$kunde}->{sdir}file\\.\" \"$kunden{$kunde}->{sdir}archiv\\$dey\\$dem\\$ded\\\"`; #jahr\monat\tag\ #$dey,$dem,$ded LOG " Kopiere 'MAIL' $kunden{$kunde}->{sdir}mail\\. ins 'ARCHIV' $kunden{$kunde}->{sdir}archiv\\$dey\\$dem\\$ded\\"; `xcopy /e /c /i /y \"$kunden{$kunde}->{sdir}mail\\.\" \"$kunden{$kunde}->{sdir}archiv\\$dey\\$dem\\$ded\\\"`; #jahr\monat\tag\ LOG " 'FILE' $kunden{$kunde}->{sdir}file\\ wird geleert"; `del /s /q \"$kunden{$kunde}->{sdir}file\\.\"`; `rmdir /s /q \"$kunden{$kunde}->{sdir}file\\.\"`; `mkdir \"$kunden{$kunde}->{sdir}file\\.\"`; LOG " 'MAIL' $kunden{$kunde}->{sdir}mail\\ wird geleert"; `del /s /q \"$kunden{$kunde}->{sdir}mail\\.\"`; `rmdir /s /q \"$kunden{$kunde}->{sdir}mail\\.\"`; `mkdir \"$kunden{$kunde}->{sdir}mail\\.\"`; LOG ""; } ##### XETRAS LOG "Xetra Reports werden kopiert"; open INI, ") { chomp; my ($source,$dest,$pdf) = split /;/,$_; my $kundecount++; LOG "Kunde $kundecount"; $source = $source . "\\" unless ($source =~ /\\$/); my $extension; if ($dest =~ /\\/) { # \ in Ziel enthalten also Pfad, d.h Dateien muessen kopiert werden LOG " Kopiere Xetra Reports von $source ==> $dest"; $dest = $dest . "\\" unless ($dest =~ /\\$/); # Sonderbehandlung fuer 886 if ($source =~ /mosfr/i) { $source = $source . $stockdate . "\\rptds*.txt"; # Börsendatum und nur Dateien eines Händlers } elsif ($source =~ /icffr_ds1/) { $source =~ s/_ds1//; $source = $source . $stockdate . "\\rptds*.txt"; } elsif ($source =~ /icffr_ds2/) { $source =~ s/_ds2//; $source = $source . $stockdate . "\\rpttc530.txt"; } else { $source = $source . $stockdate . "\\*.*"; # Brsendatum anhngen } $dest = $dest . "$dey\\$dem\\$ded\\"; LOG " xcopy $source .\\tmp\\"; `xcopy /y $source .\\tmp\\`; if ($pdf eq "pdf") { LOG " Wandle txt nach pdf um"; my @tarr=glob(".\\tmp\\*.txt"); foreach my $file (@tarr) { `txt2pdf.exe $file -pfn200 -pfs6 -ppd7`; } `del .\\tmp\\*.txt /q`; } `xcopy /y .\\tmp\\*.* $dest`; `del .\\tmp\\*.* /q`; } elsif ($dest =~ /@/) { # @ in Ziel enthalten also mail-addy, d.h. Dateien mssen gemailt werden my $archive = "$kundecount" . "_$date.zip"; # Sonderbehandlung fuer 886 if ($source =~ /mosfr/i) { LOG " Kopiere Reports nach $source\\$stockdate\\rptds. nach $archive"; #`fbzip.exe -a \"$archive\" \"$source\\$stockdate\\rptds*.txt\"`; `xcopy /y \"$source\\$stockdate\\rptds*.txt\" ".\\tmp\\"`; } else { LOG " Packe Reports nach $source\\$stockdate\\. nach $archive"; #`fbzip.exe -a \"$archive\" \"$source\\$stockdate\\*.*\"`; `xcopy /y \"$source\\$stockdate\\*.*\" ".\\tmp\\"`; } if ($pdf eq "pdf") { LOG " Wandle txt nach pdf um"; my @tarr=glob(".\\tmp\\*.txt"); foreach my $file (@tarr) { `txt2pdf.exe $file -pfn200 -pfs6 -ppd7`; } `del .\\tmp\\*.txt /q`; } `fbzip.exe -a \"$archive\" .\\tmp\\`; LOG " Maile Archiv $archive nach $dest"; `clemail -to $dest -subject \"Xetra-Reports vom $prevweekday2\" -bodyfile bodyfile.txt -attach \"$archive\" -from hotline\@icfsystems.de -smtpserver 130.35.0.141 -smtpport 25`; LOG " Loesche Archiv $archive"; `del \"$archive\"`; `del .\\tmp\\*.* /q`; } else { LOG " Ungueltiges Ziel $dest angegeben. Verarbeitung fuer diesen Kunden wird abgebrochen"; } } close INI; ($ss,$mi,$hh,$dd,$mo,$yy)=localtime; LOG "HINNE DRAA $hh:$mi:$ss\n"; LOG "--- Verarbeitung abgeschlossen ---"; sub LOG { ########################################################### # Fehlerreports in Dos Fenster ausgeben? Dann # entfernen!# ########################################################### print "@_\n"; open FIL, ">>$date.LOG"; print FIL "@_\n"; close FIL; }