Guest User

Untitled

a guest
Aug 10th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #!/bin/bash -p
  2. # Name: remoteNagiUp
  3. # Author: Richard Clark
  4. # Purpose: A post commit hook for subversion to remotely update nagios repositories
  5. # Requires: SSH Keys + Sudo configuration allowing for passphraseless authentication
  6.  
  7. REPO="$1"
  8. REV="$2"
  9.  
  10. # For post-commit hooks, no environment is setup so all commands must be full paths
  11. SVNLOOK="/usr/bin/svnlook"
  12. GREP="/bin/grep"
  13. SSH="/usr/bin/ssh"
  14. DATE="/bin/date"
  15.  
  16. echo "runnning `${DATE}`" >> /tmp/running
  17.  
  18. # Usernames
  19. NSHELLUSER="nagsvn"
  20.  
  21. # SVN Credentials
  22. SVNROUSER="theuser"
  23. SVNROPASSWD="thepassword"
  24.  
  25. # Root of all repos
  26. REPOROOT="/var/svn/nws"
  27.  
  28. BUILDSERVER="vm189.example.com"
  29. MASTERSERVER="vm234.example.com"
  30. # Add multiple slaves as needed
  31. SLAVESERVER1="vm188.example.com"
  32. ALLSERVERS=( "${BUILDSERVER}" "${MASTERSERVER}" "${SLAVESERVER1}" )
  33. SLAVESERVERS=( "${SLAVESERVER1}" )
  34.  
  35. OBJECTSCOMMON="trunk/objects_common"
  36.  
  37. # First look to see if the common directory has been updated - if so, then update all servers
  38. if ( ${SVNLOOK} dirs-changed -r ${REV} ${REPOROOT}/${REPO} | ${GREP} "^${OBJECTSCOMMON}" ); then
  39. echo "about to start loop `${DATE}`" >> /tmp/running
  40. for server in ${ALLSERVERS[*]}; do
  41. # ssh -q to avoid banner interference
  42. echo "running commands on ${server} `${DATE}`" >> /tmp/running
  43. ${SSH} -q -l ${NSHELLUSER} ${server} -t "sudo svn up /etc/nagios/objects_common --username="${SVNROUSER}" --password="${SVNROPASSWD}"" || exit 1
  44. done
  45. fi
Add Comment
Please, Sign In to add comment