1751968 Members
4444 Online
108783 Solutions
New Discussion юеВ

Re: Check consistency

 
heaman1
Regular Advisor

Check consistency

We have two servers ( server A & server B ) and have two files ( file 1 & file 2 ) , file 1 is in server A while file 2 is in server B , the file format is as attachment .

In this two files ( file 1 and file 2 ) , the file named with .txt should be the same , ( in file 2 , all file name begins with /tmp/file2 ) , the .txt file name is separated by the date string ( eg. 20090709-1930 ) , the .txt file name and date string is append to file 1 and file 2 from time to time ,

To make sure the .txt file name in both file ( file 1 and file 2 ) is consistency , I would like to regularly check the files , when found the files is not consistency ( eg. in file 1 have ???.txt while file B do have have corresponding file name in it ) , then send me a notification , can advise if I would like to check the file consistency of the same day , how can I write the script ? thx much in advance.
12 REPLIES 12
heaman1
Regular Advisor

Re: Check consistency

File 1
======

"
"
20090709-1930
20090709-2000
20090709-2030
20090709-2100
20090709-2130
aaa.txt
20090709-2200
20090709-2230
20090709-2300
20090709-2330
20090709-0000
20090710-0030
20090710-0100
20090710-0130
bbb.txt
20090710-0200
20090710-0230
20090710-0300
20090710-0330
20090710-0400
20090710-0430
20090710-0500
20090710-0530
20090710-0600
ccc.txt
20090710-0630
20090710-0700
20090710-0730
20090710-0800
20090710-0830
ddd.txt
eee.txt
fff.txt
ggg.txt
hhh.txt
20090710-0900
20090710-0930
20090710-1000
20090710-1030
20090710-1100
20090710-1130
20090710-1200
20090710-1230
20090710-1300
20090710-1330

"
"
"
heaman1
Regular Advisor

Re: Check consistency

File 2
======

"
"
20090709-1930
20090709-2000
20090709-2030
20090709-2100
20090709-2130
20090709-2200
/tmp/file2aaa.txt
20090709-2230
20090709-2300
20090709-2330
20090709-0000
20090710-0030
20090710-0100
20090710-0130
20090710-0200
/tmp/file2bbb.txt
20090710-0230
20090710-0300
20090710-0330
20090710-0400
20090710-0430
20090710-0500
20090710-0530
20090710-0600
20090710-0630
/tmp/file2ccc.txt
20090710-0700
20090710-0730
20090710-0800
20090710-0830
20090710-0900
20090710-0930
/tmp/file2/ddd.txt
/tmp/file2/eee.txt
/tmp/file2/fff.txt
/tmp/file2/ggg.txt
/tmp/file2/hhh.txt
20090710-1000
20090710-1030
20090710-1100
20090710-1130
20090710-1200
20090710-1230
20090710-1300
20090710-1330

"
"
Basheer_2
Trusted Contributor

Re: Check consistency

use diff or comm, cmp cmds to check if they are same or for any diffs
Dennis Handly
Acclaimed Contributor

Re: Check consistency

It looks like you will have to remove the "/tmp/file2" from file2 before you do the compare:
sed 's:/tmp/file2::' file2 > file2.new
heaman1
Regular Advisor

Re: Check consistency

thx replies ,

I tried the way :
sed 's:/tmp/file2::' file2 > file2.new

it seems works for a part of requirement , this is really not easy for me to complete it , I am not familiar with script writing , can anyone provide more guidance ? thx much .
I am not familiar with script
Dennis Handly
Acclaimed Contributor

Re: Check consistency

>it seems works for a part of requirement

What is the requirement? That the two files compare after removing all of the date strings?
heaman1
Regular Advisor

Re: Check consistency

thx reply ,

no need to remove anything , what I would like is to find out any file ( in file 1 and file 2 )is missing only .

thx
Dennis Handly
Acclaimed Contributor

Re: Check consistency

>what I would like is to find out any file (in file 1 and file 2) is missing only.

Something like this:
fgrep ".txt" file1 > file1.new
sed -e 's:/tmp/file2/::' -e 's:/tmp/file2::' file2 | fgrep ".txt" > file2.new
diff file1.new file2.new

rm -f file1.new file2.new
heaman1
Regular Advisor

Re: Check consistency

thx reply ,

the files are in different servers , can advise how can I use your script to compre it ? thx