compare date of files on different nodes


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users compare date of files on different nodes
# 1  
Old 03-12-2002
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





Smilie Smilie
# 2  
Old 03-12-2002
Consider using rsync. it is designed to keep files synchronized betwen two remote nodes.
# 3  
Old 03-12-2002
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  
Old 03-12-2002
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare Date to today's date in shell script

Hi Community! Following on from this code in another thread: #!/bin/bash file_string=`/bin/cat date.txt | /usr/bin/awk '{print $5,$4,$7,$6,$8}'` file_date=`/bin/date -d "$file_string"` file_epoch=`/bin/date -d "$file_string" +%s` now_epoch=`/bin/date +%s` if then #let... (2 Replies)
Discussion started by: Greenage
2 Replies

2. Shell Programming and Scripting

Compare the system date with date from a text file

I get the date that's inside a text file and assigned it to a variable. When I grep the date from the file, I get this, Not After : Jul 28 14:09:57 2017 GMT So I only crop out the date, with this command echo $dateFile | cut -d ':' -f 2,4The result would be Jul 28 14:57 2017 GMT How do I... (3 Replies)
Discussion started by: Loc
3 Replies

3. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

4. Shell Programming and Scripting

Best way to connect to hundreds of nodes and grep log files

Hi, What will be the best way to connect (ssh) to hundreds of nodes and grep log files parallely from shell. Using for loop seems to be sequential. Are there any shell built in construct which could be used to achieve this? Is the sub shell any good here? (1 Reply)
Discussion started by: agent001
1 Replies

5. Shell Programming and Scripting

Adding days to system date then compare to a date

Hi! I am trying to read a file and every line has a specific date as one of its fields. I want to take that date and compare it to the date today plus 6 days. while read line do date=substr($line, $datepos, 8) #date is expected to be YYYYMMDD if ; then ...proceed commands ... (1 Reply)
Discussion started by: kokoro
1 Replies

6. Shell Programming and Scripting

ksh compare dates INSIDE a file (ie date A is > date B)

In KSH, I am pasting 2 almost identical files together and each one has a date and time on each line. I need to determine if the first instance of the date/time is greater than the 2nd instance of the date/time. If the first instance is greater, I just need to echo that line. I thought I would... (4 Replies)
Discussion started by: right_coaster
4 Replies

7. Shell Programming and Scripting

compare date and time inside data of two files

i have two files with identical no of columns. 6th columns is date (MM/DD/YY format) and 7th columns is time (HH:MM:SS) format. I need to compare these two vaules and if the date & time is higher than fileA, save it on fileC; if the value is lower, then save it on fileD CONDITIONS... (7 Replies)
Discussion started by: ajiwww
7 Replies

8. Shell Programming and Scripting

Shell Script to compare files, check current date and count

Hello - I have written the following basic shell script to count files, compare files and look for a particular strings in a file. Problem 1: How do I define more than 1 file location? #!/bin/bash #this is a test script FILES=$(ls /home/student/bin/dir1, home/student/bin/dir2)... (0 Replies)
Discussion started by: DallasT
0 Replies

9. Shell Programming and Scripting

Compare date from db2 table to yesterday's Unix system date

I am currently running the following Korn shell script which works fine: #!/usr/bin/ksh count=`db2 -x "select count(*) from schema.tablename"` echo "count" I would like to add a "where" clause to the 2nd line that would allow me to get a record count of all the records from schema.tablename... (9 Replies)
Discussion started by: sasaliasim
9 Replies

10. Linux

compare files in the system with last modified date

HI, I have some files in my Linux machine that are very old and occupy a HUGe amount of space. I am trying to delete these files from the system so that it will be easy for me to add some files. I would like to know if this can done through a Perl or a shell script. What i want to do is i... (6 Replies)
Discussion started by: bsandeep_80
6 Replies
Login or Register to Ask a Question