LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   I'm looking for a perlscript to compare size of 2 files (https://www.linuxquestions.org/questions/programming-9/im-looking-for-a-perlscript-to-compare-size-of-2-files-148034/)

cccc 02-19-2004 10:44 AM

I'm looking for a perlscript to compare size of 2 files
 
hi

I need a perl script to compare size of 2 files ( same names )
on 2 different ftp server
and if NOT the same size send a mail to administrator.

regards
cccc

david_ross 02-19-2004 04:11 PM

Try:
Code:

#!/usr/bin/perl
@fileone=stat("/path/to/file1");
@filetwo=stat("/path/to/file2");
if($fileone[7] ne $filetwo[7]){
open(MAIL,"|/usr/lib/sendmail -t");
print MAIL <<"EOF";
to: you@host.com
from: you@host.com
subject: file1 is different from file2

Please do something about it ASAP...
 
EOF
close(MAIL);
}
exit;

Moved to programming

cccc 02-19-2004 04:38 PM

thank you very much !

cccc 02-28-2004 04:15 AM

hi david_ross

I have a serious problem with one script.
2 files ( AB1000020 and CA1000024 )
will be renamed ( to DE00000010 and EF000000011 ) according to a INFO file
and sent via ftp,
first the first one file and 5 minutes later the second one.

info file looks:

----------------------------------
AB1000020 DE00000010

CA1000024 EF000000011
----------------------------------

I cannot send the second file without the first one.
I have to be 100% sure, that the first one one file was completely transferred.

how to change this script, after first file was sent,
to compare the size of the first file ( DE00000010 )
locally at /var/ftp/files and on the ftp server
and only then send the second file ?

#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
use Net::FTP;
use Net::Netrc;

# change directory
chdir "/var/ftp/files" or die "/var/ftp/files: $!\n";

# DO NOT transfer without info file
-f "/home/ftp/files/info" or die "info file is missing\n";

open(FILE, "<info>");
while (<FILE> ) {
s/\W*$//;
next if (!$_);
/^(.+?) \s+ (.+?)$/x;

my ($old, $new) = ($1, $2);
rename $old, $new; # rename files

# ftp transfer

my $server = "X.X.X.X";
my $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3);
$ftp or die "$server: cannot connect: $@";
# If you don't use ~/.netrc
$ftp->login ('anonymous', 'address@domain.net') or
die "$_: cannot logon: " . $ftp->message;

# Put files to the ftp server
$ftp->put ($2) or
die "$server: cannot put $2: " . $ftp->message;

sleep ( 5 * 60 )

}


kind regards
cccc

david_ross 02-28-2004 08:05 AM

I haven't used Net:FTP but from the documentation it looks like there is a "size" command:
http://theoryx5.uwinnipeg.ca/CPAN/da...FTP.html#size_(_FILE_)

cccc 02-28-2004 04:45 PM

thanks, but can't find how to do that.

greetings
cccc


All times are GMT -5. The time now is 05:15 AM.