linux - Diff between two remote folders through SSH -
Do anyone know how to list files in a remote folder and not in other remote folders? I have two servers (called Server 1 and Server 2) with the same folder structure where I am Rsync However, in the Destination folder there are more files than the source because some files were deleted. Now I am trying to find a way to find which new files in Server2 using diff between Server2 and Server 2.
I can take the difference between two local folders directly using the following command:
diff / home / www / images / test_images / var / www / site / Images / test_images But I was wondering if the difference between two remote servers using SSH is possible for folders like this?
diff ubuntu1@images.server1.com: / home / www / images / test_images ubuntu2@images.server2.com: / var / www / site / images / test_images< / Pre>The SSH configuration of Server 1 and Server 2 are as follows:
Server 1
IP: Images.server1. Com user: ubuntu1 password: pa $$ word1 image path: / home / www / images / test_imagesserver2
IP: images.server2.com User: ubuntu2 Password: pa $$ Word2 Image Path: / var / www / site / images / test_imajHope any help to this problem to solve. Thank you.
Try this command:
diff-B & lt; (Find Sshpass -p 'pa $$ word1' ssh ubuntu1@images.server1.com "/ home / www / images / test_images -type f | sed 's / \ / home \ / www \ / image / test_images / / / G '"| sort-n) & lt; (Find sshpass -p 'pa $$ word2' ssh ubuntu2@images.server2.com "/ var / www / site / images / test_images -type f | sed 's / \ / var \ / www \ site / images / test_images \ /// g '"| sort -n) | Grep "& gt; | You can change thessh in two servers without interrupting your passworddiff-B & lt; () Explanation:Command first to differentiate between two currents Used in)
sshpass
sedfor each parameter specify all your images in the code To use thesearchcommand to always be listed in the list and to delete the root path of thesedfiles (because they are two heads Different for Vron - anddiffto work for the command); Andsortcommandto sort them, because
diffcommand > or>or< Lt; The result of,grep> is used to filter only one diff from your server. Last,awkprints only the second column (deletes the& gt;column from the output).Note: You must first install
sshpass. Useapt-getto set it below:sudo apt-get install sshpassOther commands like
rmare hopeful that this works for you.
Comments
Post a Comment