1826325 Members
3474 Online
109692 Solutions
New Discussion

Script Help

 
SOLVED
Go to solution
Nobody's Hero
Valued Contributor

Script Help

I need some help please. I am using 'expect' to ftp a file from one system to another but I need help with the unix front end script. I want to search one directory for a file that, always has the same name like "MDSF0011.MDS". I need to check if the date or time stamp has changed. If it does than I will execute my ftp expect script. How can I check, by a script to see if this file has changed or not?
UNIX IS GOOD
8 REPLIES 8
Rodney Hills
Honored Contributor

Re: Script Help

You may want to look into "rsync" (see porting and archive center). It is used to keep remote files "synchronized" based on date.

HTH

-- Rod Hills
There be dragons...
Nobody's Hero
Valued Contributor

Re: Script Help

I understand that. I need to run this script as an emergency. I dont have time to install any apps or modules, but thanks anyway. I know there are many utils to do this. I am going to run this on an old sco box in the field.
UNIX IS GOOD
Nobody's Hero
Valued Contributor

Re: Script Help

and in turn, ftp that file to a windoze box...
UNIX IS GOOD
Rodney Hills
Honored Contributor

Re: Script Help

If you are into "perl", their is a module called Net::ftp that creates ftp connections and allows you to manipulate the transfers/queries through objects.

Specifically method "mdtm" will return the last modify date for a remote file.

HTH

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: Script Help

Here is a small script to do a ftp get-

use Net::FTP;

$ftp = Net::FTP->new("some.host.name", Debug => 0);
$ftp->login("anonymous",'-anonymous@');
$ftp->cwd("/pub");
$ftp->get("that.file");
$ftp->quit;

HTH

-- Rod Hills
There be dragons...
Mark Grant
Honored Contributor
Solution

Re: Script Help

The important thing to remember here is that you can't rely on a string comparison of the output of "ls" because after a time "ls" stops showing the time and replaces it with the month.

With this in mind you have to use some form of the "stat()".

This works, I thinkm in perl
#!/usr/bin/perl

use File::stat;

$MYFILE="MDSF0011.MDS";
$oldmodtime=stat($MYFILE)->mtime;

while(1){
$modtime=stat($MYFILE)->mtime;
if($modtime != $oldmodtime){
'path to run my script goes here';
$modtime=$oldmodtime;
}
sleep 60;
}

Never preceed any demonstration with anything more predictive than "watch this"
Leif Halvarsson_2
Honored Contributor

Re: Script Help

Hi,

As I can see you have already got a solution for your problem but if you are interested, here is an alternative which not uses perl and which not need to run continous (you can for example run it from cron).

create a referencefile
> ref_file
update timestamp for ref_file from MDSF0011.MDS

touch -am -r MDSF0011.MDS ref_file

In your script
# chech if timestamp on MDSF0011.MDS has changed
if [ MDSF0011.MDS -nt ref_file ]
then
< do something >
# update timestamp for ref_file again
touch -am -r MDSF0011.MDS ref_file
fi
Nobody's Hero
Valued Contributor

Re: Script Help

Thanks Everyone.....
UNIX IS GOOD