Pages

Subscribe:

Thursday, 1 September 2011

Compare Two Files on 2 Servers

Q)
Hi All,

I need to compare two files, the two files available on 2 linux servers.
say, file_1 on server A
file_2 on server B

one way use ftp to download the file and compare it, other than this is there any other way? 



---
A)

Well, there is a tool called rsync that can be used to synchronize
directories between 2 remote serves.
The differential option is quite clever and can find out if 2 files are
different without having to transfer the all file and what bytes need to be
copied in order to make the files equal.

If you just need to know if the files are different you can just calculate
the checksum locally and then on the remote server.
If the two servers have different OSes you have to chose
"your_checksum_program" wisely make sure you got the same output (including
spaces, tabs and so on) when check summing the same file or else the test
"$LOCALCK" = "$REMOTECK" will fail.
You may have to do some testing to make sure that no extra text goes into
REMOTECK, system headers, motd, etc can be a pain sometimes.

LOCALCK=$(your_checksum_program your_file)
REMOTECK=$(ssh user@remoteserver "your_checksum_program your_file")
if [[ "$LOCALCK" = "$REMOTECK" ]]
then
    echo "files are the same"
else
    echo "files are different"
fi

If by some reason you can't get a clean result into REMOTECK, you may run
the checksum on the remote file and redirect the output to a temp file on
the remote system and then get that file with scp.

If you just need to know if the files are different and don't need to do it
in a script, do a checksum locally, then login in the remote server and do
the same thing.


Ant?nio Vasconcelos
Servi?o Unix
SSI UEG2 ? Gest?o de Sistemas Distr?buidos
Grupo Caixa Geral de Dep?sitos
55 67 81
email@removed

Reserva e Confidencialidade: Esta mensagem, assim como os ficheiros
eventualmente anexos, ? reservada aos seus destinat?rios, e pode conter
informa??o confidencial ou estar sujeita a restri??es legais. Se n?o ? seu
destinat?rio ou se recebeu esta mensagem por motivo de erro, solicitamos que
n?o fa?a qualquer uso ou divulga??o do seu conte?do e proceda ? elimina??o
permanente desta mensagem e respectivos anexos.

Limita??o de Responsabilidade: A CGD n?o est? vinculada ao conte?do desta
mensagem, a menos que a informa??o seja subsequentemente confirmada por um
representante autorizado da CGD. Apesar de todos os cuidados adoptados pela
CGD no sentido de preservar a seguran?a das mensagens por si enviadas, a
protec??o da informa??o enviada por via electr?nica n?o pode ser garantida
pelo remetente. Por estas raz?es, a CGD n?o se pode responsabilizar por
eventuais erros, imprecis?es ou omiss?es desta mensagem, e ficheiros
eventualmente anexos, ou por qualquer facto suscept?vel de afectar a
respectiva integridade, autenticidade ou confidencialidade. 

Editing subtitles file using awk

Q)I wanted to add 9 seconds to each of the subtitle in my file to have it in sync with video. 
I wrote an awk org for it, and it did what i was trying to do. the video is in sync with subtitles now.
now when i play the video with this new subtitles file, movie player quits when it reaches a particular subtitle. every time it quits when it reaches the same place. this does not happen with the original subtitle file.
original file

43
00:09:20,820 --> 00:09:23,618
...in which I have grown
from childhood to a man!

44
00:09:24,757 --> 00:09:26,554
I had sworn by those
alps and peaks...



edited file

43
00:09:29,820 --> 00:09:32,618
...in which I have grown
from childhood to a man!

44
00:09:33,757 --> 00:09:35,554
I had sworn by those
alps and peaks...


movie player after showing the underlined text.

Any idea why this happens??

i am running mint 10- julia, Totem Movie Player 2.32.0 
--------------------------
A)#!/usr/bin/awk -f 
BEGIN {
FIELDWIDTHS="3 2 1 2 12 2 1 2 4"
OFS=""
}

/-->/ {
if ($4>21)
{
$4=$4-21;
if ($4<10)
{
$4=0$4
}
}
else
{
$4=60-(21-$4);
$2=$2-1;
if ($2<10)
{
$2=0$2;
}
};
if ($8>21)
{
$8=$8-21;
if ($8<10)
{
$8=0$8

}
}
else
{

$8=60-(21-$8);
$6=$6-1;
if ($6<10)
{
$6=0$6;
}
};

print $1,$2,$3,$4,$5,$6,$7,$8,$9}
$0 !~ /-->/ {print $0}