Leser: 1
|< 1 2 3 >| | 22 Einträge, 3 Seiten |
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
#!/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 for the first file
$ftp->cwd("/DE/IN");
# 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 10 minutes\n";
sleep (10 * 60);
}
$ftp->quit;
# And wait 15 minutes
sleep (15 * 60);
}
# read the log file
my $content;
open(FILE, "/var/ftp/log/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 was successfully !\n";
print MAIL "hi \n\n";
print MAIL "ftp transfer was successfully ! \n\n";
print MAIL "log file: \n";
print MAIL "$content \n\n";
print MAIL "Time: ", scalar localtime, "\n";
close(MAIL);
exit;
$ftp->put ($f2) and last; # Success
QuoteReturns "REMOTE_FILE", or the generated remote file-
name if "REMOTE_FILE" is not given.
NOTE: If for some reason the transfer does not com-
plete and an error is returned then the contents that
had been transfered will not be remove automatically.
while(<FILE>) { $content .=$_; }
{ local $/; $content = <FILE>; }
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
@ARGV = ("info");
my @ren;
while (<>) { # for every line in info
m/^\s*(\S+)\s+(\S+)\s*$/ or next; #
-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 ];
$ren[0]->[2] = "/DE/IN";
$ren[1]->[2] = "/DE/OUT";
}
..............
..............
# 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
my ($f1, $f2, $ftp_upload_location) = @$f
$ftp->cwd ($ftp_upload_location);
..............
..............
1
2
3
4
5
6
7
8
9
10
11
12
# 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
my ($f1, $f2, $ftp_upload_location) = @$f;
$ren[0]->[2] = "/DE/IN";
$ren[1]->[2] = "/DE/OUT";
$ftp->cwd ($ftp_upload_location);
|< 1 2 3 >| | 22 Einträge, 3 Seiten |