compare date of files on different nodes

Hi All,

I�ve got the following problem

I�m implementing a failoverconcept. This requires to synchronize two files using ksh like this.

if HOST1:FILE1 is newer then HOST2:FILE1
THEN cp HOST1:FILE1 HOST2:FILE1
ELSE cp HOST2:FILE1 HOST1:FILE1
fi

How can I compare the files on two boxes?

I tried it on one box and it works

and im able to get the date information with ls -l and awk - like this but how i schould compare the datestrings or how can i change the variable format?

DATE_MAIN=`ls -l FILE1 | awk '$1 !~ /total/ { printf "%-32s \n",$8 ; }'`

DATE_BCKP=`rsh HOST2 ls -l FILE1 | awk '$1 !~ /total/ { printf "%-32s \n",$8 ; }'`

if [ $DATE_MAIN -ge $DATE_BCKP ]
THEN cp HOST1:FILE1 HOST2:FILE1
ELSE cp HOST2:FILE1 HOST1:FILE1
fi

An other idea i got was using the find command with the -newer flag but it didn�t work with an remote Host.

BRGDS & TIA

isacs

P.S.

Sorry for my poor english

:eek: :eek:

Consider using rsync. it is designed to keep files synchronized betwen two remote nodes.

THX PxT,

I think this will meet my expectations, but due to internal guidelines we�re not allowed to use OpenSource.
SO I only can use the SOLARIS tools or programs delivered by SUN.

BRGDS

isacs

There are several problems with doing this via ls. The first is that ls switches formats for old files add shows just the year. All we can do if a case like that is guess as to time. And if it is showing the time, you can just assume the year is the current year because files dated late last year will not have switched formats to show the year. And Solaris adds a problem in that it allows long user names and group names but if you them, the fields in ls overflow and run together.

Here is a script that does the best that can be done under the circumstances:

#! /usr/bin/ksh

file=$1

set +A  ls  -  $(ls -lL $file)
Jan=01; Feb=02; Mar=03; Apr=04; May=05; Jun=06; 
Jul=07; Aug=08; Sep=09; Oct=10; Nov=11; Dec=12;

eval month=\$${ls[${#ls[*]} - 4]}
if [[ ${ls[${#ls[*]} - 2]} = *:* ]] ; then
	year=$(date +%Y)
	thismonth=$(date +%m)
	((thismonth < month)) && ((year=year-1))
	time=${ls[${#ls[*]} - 2]}
else
	year=${ls[${#ls[*]} - 2]}
	time=00:00
fi

echo ${year}${month}${day}${time%%???}${time##???}
exit 0