| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
#********************************************************************* |
| 4 |
# |
| 5 |
# fai-savelog-ftp -- save log files from fai to FTP server |
| 6 |
# |
| 7 |
# This script is part of FAI (Fully Automatic Installation) |
| 8 |
# |
| 9 |
#********************************************************************* |
| 10 |
# This program is free software; you can redistribute it and/or modify |
| 11 |
# it under the terms of the GNU General Public License as published by |
| 12 |
# the Free Software Foundation; either version 2 of the License, or |
| 13 |
# (at your option) any later version. |
| 14 |
# |
| 15 |
# This program is distributed in the hope that it will be useful, but |
| 16 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 |
# General Public License for more details. |
| 19 |
# |
| 20 |
# A copy of the GNU General Public License is available as |
| 21 |
# '/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution |
| 22 |
# or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You |
| 23 |
# can also obtain it by writing to the Free Software Foundation, Inc., |
| 24 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 25 |
#********************************************************************* |
| 26 |
|
| 27 |
use strict; |
| 28 |
use Net::FTP; |
| 29 |
|
| 30 |
chomp (my $hostname = `hostname`); |
| 31 |
|
| 32 |
print "Save log files via FTP to $ENV{LOGUSER}\@$ENV{LOGSERVER}:$hostname/$ENV{FAI_ACTION}-$ENV{fai_rundate}\n"; |
| 33 |
|
| 34 |
my $ftp = Net::FTP->new("$ENV{LOGSERVER}", Debug => 0) |
| 35 |
or die "Cannot connect to FTP server $ENV{LOGSERVER}.\n"; |
| 36 |
$ftp->login("$ENV{LOGUSER}", "$ENV{LOGPASSWD}") |
| 37 |
or die "Cannot login to FTP server $ENV{LOGSERVER} with login $ENV{LOGUSER}.\n"; |
| 38 |
$ftp->cwd("$ENV{LOGREMOTEDIR}") |
| 39 |
or die "Cannot change work directory to $ENV{LOGREMOTEDIR}\n"; |
| 40 |
my $ftplogdir = $ftp->mkdir("$hostname/$ENV{FAI_ACTION}-$ENV{fai_rundate}", 1) |
| 41 |
or die "Cannot create dir $ENV{FAI_ACTION}-$ENV{fai_rundate}.\n"; |
| 42 |
$ftp->cwd("$ftplogdir") |
| 43 |
or die "Cannot change work directory to $ftplogdir.\n"; |
| 44 |
|
| 45 |
while (my $file = <$ENV{LOGDIR}/*>) { |
| 46 |
$ftp->put("$file"); |
| 47 |
} |
| 48 |
|
| 49 |
$ftp->quit; |