Created
December 6, 2012 21:49
-
-
Save starkfell/4228812 to your computer and use it in GitHub Desktop.
Bash Script used to update multiple NRPE Agents on multiple hosts from a text file.
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 | |
| # | |
| # NRPE Multi-Agent Updater Script | |
| # | |
| # Author : Ryan Irujo | |
| # Inception: 03.07.2012 | |
| # | |
| # Description: Bash Script used to update multiple NRPE Agent on multiple hosts listed in a text file | |
| # called 'hosts.txt'. | |
| # | |
| # Notes: DO NOT RUN THIS SCRIPT AS ROOT! Run this script ONLY using a Service or User Account | |
| # | |
| # How To Use: You will be prompted twice for the password for each host you are updating. Keeping | |
| # the User or Service Account Password available for Copy/Paste is handy here. | |
| # | |
| # To add/remove hosts you want to update, edit the 'hosts.txt' file in the | |
| # /home/howler/export/ directory accordingly. | |
| if [ "$1" = "" ]; then | |
| echo "Please provide the [Release] you want to install, i.e. - 1.2, 1.4, etc..." | |
| exit 2; | |
| #elif [ $VARIABLE -eq $VARIABLE 2> /dev/null ]; then | |
| elif [ $1 = $1 ]; then | |
| echo "*****************************************" | |
| echo "`cat hosts.txt`"; | |
| echo "mon-nrpe-plugin-2.12-$1.x86_64.rpm will be installed on the server(s) in \"hosts.txt\":ok?[yes/no]"; | |
| read response | |
| if [ $response == "no" ]; then | |
| echo "Exiting Script..."; | |
| exit 2; | |
| elif [ $response == "yes" ]; then | |
| for host in `cat hosts.txt`; | |
| do | |
| scp /home/howler/export/mon-nrpe-plugin-2.12-$1.x86_64.rpm howler@$host:/home/howler ; | |
| ssh -t $host " rpm -qa mon-nrpe-plugin | |
| sudo /bin/rpm -e mon-nrpe-plugin | |
| sudo /bin/rpm -i mon-nrpe-plugin-2.12-$1.x86_64.rpm | |
| /usr/lib64/nagios/plugins/check_nrpe -H localhost | |
| rm -rf mon-nrpe-plugin-2.12-* && echo 'RPMs have been cleaned out of the home directory.'" ; | |
| done | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment