Schrift
[thread]6114[/thread]

manchmal ist es NICHT einfach ! (Seite 3)

Leser: 1


<< |< 1 2 3 >| >> 22 Einträge, 3 Seiten
cc
 2004-03-12 01:02
#80539 #80539
User since
2004-01-09
55 Artikel
BenutzerIn
[default_avatar]
hi

habe aber noch ein anderes problem und vestehe nicht, warum.
nach dem korrekten transfer: zuerst das erste file und 15 minuten das zweite, das script wartet noch zusätzlich
ca. 1 halbe stunde und erst dann schickt eine abschluss mail mit dem log inhalt.
weiss jemand vielleich warum und wie ich es ändern kann ?

ganzes script sieht so aus:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/perl -w
use strict;
use warnings;
use File::Copy;
use Net::FTP;
use Net::Netrc;

# write the log
BEGIN
{
use CGI::Carp qw(carpout);
my $errorlog = "/var/ftp/log/errorlog.txt";
open(LOG, ">$errorlog") or die("Unable to open $errorlog: $!\n");
print LOG "Errors:\n";
carpout(*LOG);
}

my $recipient = "adress\@domain.de";
my $linux = "root\@domain.de";
my $server = "X.X.X.X";
my $user = "anonymous";
my $passwd = "";

chdir "/var/ftp" or die "/var/ftp: $!\n";

# DO NOT transfer without info file
-f "/var/ftp/info" or die "info file IS MISSING !\n";

# open and read info file
@ARGV = ("info");
my @ren;
while (<>) { # for every line in info
m/^\s*(\S+)\s+(\S+)\s*$/ or next; # That matches like "XXXXXXXX XXXXXXXX"
-f $1 or next; # skip if file to rename does not exist
-f $2 and next; # skip if file to rename does not exist
push @ren, [ $1, $2 ];
}

unless (@ren == 2) {
die "files are NOT complete !\n";
# extend to your feeling
}

# rename files according to info file
foreach my $f (@ren) {
my ($f1, $f2) = @$f;
move ($f1, $f2); # Rename files

# ftp transfer
my $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3);
$ftp or die "$server: cannot connect: $@";
# If you don't use ~/.netrc
$ftp->login ($user,$passwd) or
die "$_: Could not login: " . $ftp->message;

# change remote directory
$ren[0]->[2] = "/DE/IN";
$ren[1]->[2] = "/DE/OUT";
my ($ft1, $ft2, $ftp_upload_location) = @$f;
$ftp->cwd ($ftp_upload_location);

# Put file 2 (not 1) to the ftp server
# server might go down, so retry twice
foreach my $try (0 .. 2) {
$ftp->put ($f2) and last; # Success
if ($try == 2) {

# send mail when transfer of second file failed
open(MAIL, "|/usr/sbin/sendmail -t");
print MAIL "from:$linux\n";
print MAIL "to:$recipient\n";
print MAIL "subject:ftp transfer of second file failed ! !\n";
print MAIL "hi \n\n";
print MAIL "ftp transfer of second file failed !\n\n";
print MAIL "Time: ", scalar localtime, "\n";
close(MAIL);

die "$server: cannot put $f2: " . $ftp->message;
}
print STDERR "Trasfer of $f2 failed: ",$ftp->message, ", retry in 15 minutes\n";
sleep (15* 60);
}
$ftp->quit;

# And wait 15 minutes
sleep (15 * 60);
}

# create backup subfolder when transfer completed with date and time
my @dt = localtime;
my $subfolder_name = ((((1900 + $dt[5]) * 100 + 1 + $dt[4]) * 100 + $dt[3]) * 100 + $dt[2]) * 100 + $dt[1];
mkdir "/srv/ftp/OUT/$subfolder_name" or die "$subfolder_name: $!";

# backup 2 date files, info and errorlog to the subfolder in the OUT directory
# and remove all files from the old location
foreach my $ft2 (map { $_->[1] } @ren) {
move $ft2, "/var/ftp/OUT/$subfolder_name/$ft2";
move "info", "/var/ftp/OUT/$subfolder_name/info";
move "/var/ftp/logs/errorlog.txt", "/var/ftp/OUT/$subfolder_name/errorlog.txt";
}

# read the log file
my $content;
open(FILE, "/var/ftp/OUT/$subfolder_name/errorlog.txt") || die "Cant open file. Reason: $!"; # (-:
while(<FILE>) {
$content .=$_; # get all of the file into content including past new lines
}
close(FILE);

# send the mail with log contents, when transfer completed
open(MAIL, "|/usr/sbin/sendmail -t") || die "Cant send mail. Reason: $!";
print MAIL "from:$linux\n";
print MAIL "to:$recipient\n";
print MAIL "subject:transfer of 2 files was successfully !\n";
print MAIL "hi \n\n";
print MAIL "ftp transfer of 2 files was successfully ! \n\n";
print MAIL "log file: \n";
print MAIL "$content \n\n";
print MAIL "Time: ", scalar localtime, "\n";
close(MAIL);

exit;
\n\n

<!--EDIT|cc|1079046245-->
cc
 2004-03-25 16:13
#80540 #80540
User since
2004-01-09
55 Artikel
BenutzerIn
[default_avatar]
weiss vielleicht jemand was da falsch ist
oder wie man es ändern kann ?

gruss
cc
<< |< 1 2 3 >| >> 22 Einträge, 3 Seiten



View all threads created 2004-03-03 11:55.