Results 1 to 4 of 4
Hi
I am new to scripting and to prove myself at work i've to do a script that would compare directories and files between two serverst, then the result should ...
- 02-28-2010 #1Just Joined!
- Join Date
- Feb 2010
- Location
- melbourne, Australia
- Posts
- 5
shell script to compare the files between two servers
Hi
I am new to scripting and to prove myself at work i've to do a script that would compare directories and files between two serverst, then the result should go to a remote server.
Please guys help me with this, even a small example would help. I am sure there is lot of genius in this community!!
regards
chetan
- 02-28-2010 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Not sure what you mean by 'compare directories and files between two serverst'. Anyway I'll use the 'find' command as an example.
You can use 'ssh' to execute a command on the remote server and redirect the output to a file. Here I use 'find' to list all files/directories in the home directory.
Then you can use scp to copy the results to the remote server.
Note that I use private/public ssh keys so the script won't ask for passwords.Code:#!/bin/bash -vx ssh -x -i ~/.ssh/id_rsa server2 find . > files.txt (do your comparisons here directing the output to result.txt) scp -i ~/.ssh/id_rsa result.txt server2:
- 03-02-2010 #3
there are 2 ways to interpret this. Are you wanting to see if there is a difference of what files are on the server, or to take a local and remote file, and see what is different about them?
New to the internet, technical forums, or the hacker / open source community??
Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html
RHCE for RHEL version 5
RHCT for RHEL version 4
- 03-08-2010 #4Just Joined!
- Join Date
- Feb 2010
- Location
- melbourne, Australia
- Posts
- 5
Hi Guys
First of all thanks for your assistance!!
Secondly i had a bit of a misunderstanding with my boss about what he exactly wanted.
The prick actually wants to see differences of what files are on the server compared to the fles and directories on the other server.
He actually doesn't want a script, he would like me to run commands to do this task.
So this is what i did:
1)On server A i did "ls -R >> outputA.txt"
2)On server B i did "ls -R >>outputB.txt"
Then brought outptB.txt to A server and ran sdiff command but by doing this it has so much garbage that i don't want!!
By garbage what i mean is "directory paths and duplicate files" and i need help on filtering!!
I am hoping if there is a simpler way of doing this!!
I hope i making things clear for you smart people!!
Thanks once again guys!!


Reply With Quote
