Power to Build

Home » Misc » Quick Tip: Unix diff remote file and a local file

Quick Tip: Unix diff remote file and a local file

Suppose you have a copy of your Unix script (or any other text file) on 2 different servers. You can ftp the file (or scp) to the machine you are and then do a diff. But, if you are in a hurry and just need to check if the files are the same, you can use the below techique:

ssh svaradar@<remoteserver> "cat /app/myApp/script/mytestscript.ssh" | diff - /app/myApp/script/mytestscript.ssh

(names have been changed for this example)

The syntax is ssh <userid>@<remoteserver> ‘<command>’. Of course, you need to have an eligible logon on the remote server. And when you run this, it will ask you for the remote server password.

You are essentially logging into a Secured shell and run the command inside double quotes once. Here I am cat’ing the remote file and pipe that into the diff command.

Such is the power of *nix. To do this in Windows, it takes lot more than that. SysInternals Suite of course, has programs to run command remotely. I will post that later.

Update, 4/28: And for diffing/comparing directories on different servers, please this post on StackOverflow.

 


Comments, please?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: