Advertisement
Guest User

Untitled

a guest
Nov 1st, 2010
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. #  Check saved file md5sum's against current md5sum's to
  4. #  monitor for changes in file content.
  5. #  Assumes that the /etc/nagios/md5s file has already been
  6. #  generated on the client for use with "md5sum -c FILE"
  7. #  
  8. #  To use add a new NRPE service that executes check_file_md5s
  9. #  and define the command in nrpe.cfg on the client
  10. #
  11. #  Author:  Stephen Berg, Jacobs Contractor, Naval Research Lab
  12. #           Stennis Space Center, MS
  13. current_md5s=`mktemp`
  14. saved_md5s=/etc/nagios/md5s
  15.  
  16. STATE_OK=0
  17. STATE_WARNING=1
  18. STATE_CRITICAL=2
  19. STATE_UNKNOWN=3
  20. STATE_DEPENDENT=4
  21.  
  22. /usr/bin/md5sum -c $saved_md5s > $current_md5s 2>&1
  23.  
  24. file_count=`wc -l $saved_md5s | awk '{ print $1 }'`
  25. ok_count=`/bin/grep -c OK $current_md5s`
  26. failed_count=`/bin/grep -c FAILED $current_md5s`
  27.  
  28. if [ $ok_count -eq $file_count ]
  29. then
  30.     echo "All monitored files (${ok_count}/${file_count}) are OK."
  31.     cat ${current_md5s}
  32.     /bin/rm ${current_md5s}
  33.     exit $STATE_OK
  34. else
  35.     grep WARNING $current_md5s
  36.     grep FAILED $current_md5s
  37.     cat ${current_md5s} | grep OK
  38.     /bin/rm ${current_md5s}
  39.     exit $STATE_WARNING
  40. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement