cancel
Showing results for 
Search instead for 
Did you mean: 

Diff command

SKR_1
Trusted Contributor

Diff command

Hi

Can we use diff command to differentiate files on two servers.

Thanks

SKR
13 REPLIES
Dennis Handly
Acclaimed Contributor

Re: Diff command

You can only do this if one file is over NFS and you use that path.
SKR_1
Trusted Contributor

Re: Diff command

Hi Dennis,

Can you give me one line script which will cat the file from other server with doing ssh/rmesh/rsh and can be diff with file present on current server.

Thanks

SKR
Venkatesh BL
Honored Contributor

Re: Diff command

If you want to compare a local '/tmp/abc' file with the same file in another server 'xyz', you could do:
1) rcp xyz:/tmp/abc /tmp/abc.xyz
2) diff /tmp/abc /tmp/abc.xyz

Once done, you could delete the 'abc.xyz' file from the local machine.

This is one way. If you can NFS mount this directory from the other server, then you can directly do:
# diff /tmp/abc /mntpoint-of-server-dir/abc
Dennis Handly
Acclaimed Contributor

Re: Diff command

>Can you give me one line script which will cat the file from other server with doing ssh/remsh/rsh and can be diff with file present on current server.

Ah, right you can do that:
remsh remote -n "cat remote-file-path" | diff - local-file-path
SKR_1
Trusted Contributor

Re: Diff command

Hi Dennis,

Still i am not able to diff these files.

I am able to cat the file, but diff is not working.

Thanks

SKR
Steven E. Protter
Exalted Contributor

Re: Diff command

Shalom,

I have always used diff in one of two ways:

1) took a copy of the files and ran it local
2) Established an nfs connection.

Note that you can not use diff successfully on binary files

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: Diff command

>I am able to cat the file, but diff is not working.

I assume you can do:
remsh remote -n "cat remote-file-path" | more

What command did you use? What do you mean "not working"? I hope you kept that "-" I had.
Dennis Handly
Acclaimed Contributor

Re: Diff command

>SEP: Note that you can not use diff successfully on binary files

If you consider "success" as an exact match or just knowing the files are different, you can.
Kapil Jha
Honored Contributor

Re: Diff command

what command exactly you are running ,have you copied the file locally,what is the error you are getting.

diff file1 file2
is the command.

Thanks,
Kapil+
I am in this small bowl, I wane see the real world......
SKR_1
Trusted Contributor

Re: Diff command

I dont want to copy the file of another server to local server, i just want to cat that remote file and do diff with local file.

Hi Dennis,

i am giving below command.

remsh remoteserver -n " cat filepath" | diff localfilepath

Thanks

SKR
SKR_1
Trusted Contributor

Re: Diff command

Tried below full command

serverA:/usr/local/ADMIN/crondir >remsh serverB -n "cat /usr/local/ADMIN/crondir/sysbackup.ksh" | diff sysbackup.ksh
usage: diff [ -C n ] [ -S name ] [ -bcefhilnrstw ] dir1 dir2
diff [-C n ] [ -bcefhintw ] file1 file2
diff [ -D string ] [ -biw ] file1 file2
remsh_[7]: title: not found

remsh to serverB is working fine, tried with -n option & without -n option also, but no luck

Thanks

SKR

Steven Schweda
Honored Contributor

Re: Diff command

> | diff - local-file-path

> I hope you kept that "-" I had.

> | diff localfilepath

Well, duh.
Dennis Handly
Acclaimed Contributor

Re: Diff command

>remsh remoteserver -n " cat filepath" | diff localfilepath

As I mentioned twice, you need that "-". That tells diff to compare the file vs stdin from the remsh/cat pipe.