Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -p
- # Name: remoteNagiUp
- # Author: Richard Clark
- # Purpose: A post commit hook for subversion to remotely update nagios repositories
- # Requires: SSH Keys + Sudo configuration allowing for passphraseless authentication
- REPO="$1"
- REV="$2"
- # For post-commit hooks, no environment is setup so all commands must be full paths
- SVNLOOK="/usr/bin/svnlook"
- GREP="/bin/grep"
- SSH="/usr/bin/ssh"
- DATE="/bin/date"
- echo "runnning `${DATE}`" >> /tmp/running
- # Usernames
- NSHELLUSER="nagsvn"
- # SVN Credentials
- SVNROUSER="theuser"
- SVNROPASSWD="thepassword"
- # Root of all repos
- REPOROOT="/var/svn/nws"
- BUILDSERVER="vm189.example.com"
- MASTERSERVER="vm234.example.com"
- # Add multiple slaves as needed
- SLAVESERVER1="vm188.example.com"
- ALLSERVERS=( "${BUILDSERVER}" "${MASTERSERVER}" "${SLAVESERVER1}" )
- SLAVESERVERS=( "${SLAVESERVER1}" )
- OBJECTSCOMMON="trunk/objects_common"
- # First look to see if the common directory has been updated - if so, then update all servers
- if ( ${SVNLOOK} dirs-changed -r ${REV} ${REPOROOT}/${REPO} | ${GREP} "^${OBJECTSCOMMON}" ); then
- echo "about to start loop `${DATE}`" >> /tmp/running
- for server in ${ALLSERVERS[*]}; do
- # ssh -q to avoid banner interference
- echo "running commands on ${server} `${DATE}`" >> /tmp/running
- ${SSH} -q -l ${NSHELLUSER} ${server} -t "sudo svn up /etc/nagios/objects_common --username="${SVNROUSER}" --password="${SVNROPASSWD}"" || exit 1
- done
- fi
Add Comment
Please, Sign In to add comment