Operating System - Linux
1830231 Members
1754 Online
109999 Solutions
New Discussion

need a perl script to compare size of 2 files

 
SOLVED
Go to solution
'chris'
Super Advisor

need a perl script to compare size of 2 files

hi

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

kind regards
chris
7 REPLIES 7
Steven E. Protter
Exalted Contributor

Re: need a perl script to compare size of 2 files

Hi Chris:

There may be something you need at Merijn's site http://www.hpux.ws/merijn

Or try a thread in HP-UX languages. Then A.Clay Stephenson will see it and post something up for you.

I'm working on a perl script right now, or I'd try and hack it for you. The Languages forum has more traffic than Linux so its more likely to get you an answer.

If you don't have a solution when I'm done with my script, I'll take a "hack" at it.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Mark Grant
Honored Contributor
Solution

Re: need a perl script to compare size of 2 files

I wish I knew more about what you have and what you need because this is a nasty script but it works.

#!/usr/bin/perl

use Net::FTP;

$ftp=Net::FTP->new("host1", Debug => 0);
$ftp->login("user","password");
$SIZE=$ftp->size($ARGV[0]);
$ftp->quit;
$ftp=Net::FTP->new("host2", Debug => 0);
$ftp->login("user","password");
$SIZE1=$ftp->size($ARGV[1]);
$ftp->quit;

if($SIZE1 != $SIZE){
`echo $ARGV[0] is not the same size as $ARGV[1]|mailx -s "Subject" email
`;
}
Never preceed any demonstration with anything more predictive than "watch this"
Mark Grant
Honored Contributor

Re: need a perl script to compare size of 2 files

oops, forgot to tell you how to run it.

if script is called "ftptest.pl" then run as

"ftptest.pl file1 file2"

Never preceed any demonstration with anything more predictive than "watch this"
'chris'
Super Advisor

Re: need a perl script to compare size of 2 files

thank you very much.
it helps a lot.

but ist it possible to put the name of this
file as a variable for example:
$file
to the script,
because it will be the same file on both
server ( the same name also ).
I mean the script will be started only with: ftptest.pl

this file will be transfered via ftp
at night from one ftp server to another.
only the size will change.

what I need next day in the morning
is it to control if the file was transfered
successfully or not.

kind regards
chris
Martin P.J. Zinser
Honored Contributor

Re: need a perl script to compare size of 2 files

Hello Chris,

small variations to the theme:

#!/usr/bin/perl

use Net::FTP;

$file = "put your filename here";
$ftp=Net::FTP->new("host1", Debug => 0);
$ftp->login("user","password");
$SIZE=$ftp->size($file);
$ftp->quit;
$ftp=Net::FTP->new("host2", Debug => 0);
$ftp->login("user","password");
$SIZE1=$ftp->size($file);
$ftp->quit;

if($SIZE1 != $SIZE){
`echo $file is out of synch|mailx -s "Subject" email
`;
}

It should be obvious where to plug the filename :-)

Greetings, Martin
'chris'
Super Advisor

Re: need a perl script to compare size of 2 files

thanks,

but this srcript wont run properly.
Stuart Browne
Honored Contributor

Re: need a perl script to compare size of 2 files

Right then.. what does it do?

Try changing the DEBUG=>'s to 1, instead of 0 to get more details, to see where it falls over.
One long-haired git at your service...