LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-19-2004, 10:44 AM   #1
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,613

Rep: Reputation: 47
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
 
Old 02-19-2004, 04:11 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
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

Last edited by david_ross; 02-19-2004 at 04:15 PM.
 
Old 02-19-2004, 04:38 PM   #3
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,613

Original Poster
Rep: Reputation: 47
thank you very much !
 
Old 02-28-2004, 04:15 AM   #4
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,613

Original Poster
Rep: Reputation: 47
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

Last edited by cccc; 02-28-2004 at 05:31 PM.
 
Old 02-28-2004, 08:05 AM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
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_)
 
Old 02-28-2004, 04:45 PM   #6
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,613

Original Poster
Rep: Reputation: 47
thanks, but can't find how to do that.

greetings
cccc

Last edited by cccc; 02-29-2004 at 05:58 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I compare 2 files? linuxhippy Slackware 6 03-26-2005 01:54 AM
Diff compare 2 files DavidTempler Linux - Newbie 2 11-01-2004 10:00 AM
I'm looking for perlscript to delete some files via ftp cccc Programming 1 02-24-2004 01:56 AM
need a perlscript to read from a text file and transfer files via ftp cccc Linux - Networking 2 02-21-2004 06:18 PM
to compare the contents of 2 files MaleWithBrains Linux - Newbie 3 01-27-2004 06:39 PM


All times are GMT -5. The time now is 03:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration