The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare date from db2 table to yesterday's Unix system date sasaliasim Shell Programming and Scripting 8 04-24-2008 03:04 AM
compare files in the system with last modified date bsandeep_80 Linux 6 01-14-2008 08:56 PM
compare date with date in file siog UNIX for Dummies Questions & Answers 2 10-04-2006 09:10 AM
compare today's date with date in a file siog UNIX for Dummies Questions & Answers 4 10-04-2006 08:55 AM
compare date vanand420 Shell Programming and Scripting 5 09-01-2005 01:13 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-12-2002
Registered User
 

Join Date: Mar 2002
Location: Muenster - Germany
Posts: 22
Stumble this Post!
Question 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





Forum Sponsor
  #2 (permalink)  
Old 03-12-2002
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Stumble this Post!
Consider using rsync. it is designed to keep files synchronized betwen two remote nodes.
  #3 (permalink)  
Old 03-12-2002
Registered User
 

Join Date: Mar 2002
Location: Muenster - Germany
Posts: 22
Stumble this Post!
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
  #4 (permalink)  
Old 03-12-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,449
Stumble this Post!
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:
Code:
#! /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
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0