Created
September 20, 2019 20:01
-
-
Save planetceres/bdac340ce9403ed6f960f4f37aed4b64 to your computer and use it in GitHub Desktop.
Compare ubuntu packages between two hosts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Reference: https://askubuntu.com/a/344396 | |
function _compare_hosts () { | |
echo "Usage: $ ./compare_pkgs.sh username@ip_address1 username@ip_address2 ~/.ssh/id_rsa1 ~/.ssh/id_rsa2" | |
# 1: remote_host = user@ip_address | |
# 2: ssh_key = ~/.ssh/id_rsa | |
if [[ ! -z $1 ]]; then | |
local remote_host1=$1 | |
else | |
read -p "Enter remote host1 (ex: user@ip_address): " remote_host | |
fi | |
if [[ ! -z $2 ]]; then | |
local remote_host2=$2 | |
else | |
read -p "Enter remote host2 (ex: user@ip_address): " remote_host | |
fi | |
if [[ ! -z $3 ]]; then | |
local ssh_key1="-i $3" | |
else | |
local ssh_key1="" | |
fi | |
if [[ ! -z $4 ]]; then | |
local ssh_key2="-i $4" | |
else | |
local ssh_key2="" | |
fi | |
ssh $ssh_key1 $remote_host1 dpkg --get-selections | grep '\binstall$' | cut -f 1 > server-host1.txt | |
ssh $ssh_key2 $remote_host2 dpkg --get-selections | grep '\binstall$' | cut -f 1 > server-host2.txt | |
comm -12 <(sort server-host1.txt) <(sort server-local.txt) > server-host1-and-local.txt | |
comm -23 <(sort server-host1.txt) <(sort server-local.txt) > only-server-host1.txt | |
comm -13 <(sort server-host1.txt) <(sort server-local.txt) > only-server-local.txt | |
echo $(wc -l *.txt) | |
} | |
_compare_hosts "${@}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment