Skip to content

Instantly share code, notes, and snippets.

@Avyd
Last active December 23, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Avyd/6652791 to your computer and use it in GitHub Desktop.
Save Avyd/6652791 to your computer and use it in GitHub Desktop.
This script started from a jump server will copy and install a specified rpm package from one server to an other. It is useful if the given two servers has no connection with each other. It uses RedHat's "yum".
#Specify the settings and make sure you have a "results" folder
#"rpm_server" --> rpm will be downloaded here
#"server" ---> rpm will be installed here
#"up2date_ver" -> current version of rpm pack
rpm_server=server_name
server=server_name
up2date_ver=$(echo "server_name")
#Check version on the given server
version_check=$(ssh $server -l root -o StrictHostKeyChecking=no -o BatchMode=yes -C "rpm -qa | grep lsy_root_authorized" > /dev/null)
echo "$server :$version_check" >> results/server_and_version
#Check if the rpm package is updated or not
#If it's ok, it won't modify anything
cur_version=$(cat results/server_and_version | grep $server | cut -d: -f 2)
if [ "$up2date_ver" == "$cur_version" ]
then
echo "LSY auth files are up to date!"
else
echo "Warning - LSY auth files are not up to date!"
fi
#Clear the result file to prevent fake checks
date=$(date +"%y-%m-%d_%H:%M:%S")
cp results/server_and_version results/server_and_version_$date
echo > results/server_and_version
#Else
#1. Download rpm from RHN to $rpm_server
#2. Scp the rpm file to windu
#3. Scp the rpm file from windu to the SuSe server
#4. Install the rpm package
#5. Delete the rpm file from the server
echo "Running yumdownloader"
ssh $rpm_server -l root -o StrictHostKeyChecking=no -o BatchMode=yes -C "yumdownloader lsy_root_authorized-*" > /dev/null
echo "Running scp to windu"
scp -o BatchMode=yes root@$rpm_server:/root/lsy_root_authorized-* results/ > /dev/null
echo "Running scp from windu to SuSe"
scp -o BatchMode=yes results/lsy_root_authorized-* root@$server:/root/ > /dev/null
echo "Installing rpm..."
ssh $server -l root -o StrictHostKeyChecking=no -o BatchMode=yes -C "rpm -i /root/lsy_root_authorized-*"
echo "Cleaning up"
ssh $server -l root -o StrictHostKeyChecking=no -o BatchMode=yes -C "rm /root/lsy_root_authorized-*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment