check_smb.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash
  2. #
  3. # Program : check_smb
  4. # :
  5. # Author : Cal Evans <cal@calevans.com>
  6. # :
  7. # Purpose : Nagios plugin to return the number of users logged into a smb
  8. # : server and the number of files open.
  9. # :
  10. # Parameters : --help
  11. # : --version
  12. # :
  13. # Returns : Standard Nagios status_* codes as defined in utils.sh
  14. # :
  15. # Notes :
  16. #============:==============================================================
  17. # 1.0 : 06/27/2002
  18. # : Initial coding
  19. # :
  20. # 1.1 : 06/28/2002
  21. # : Re-wrote the user counter to match the file-lock counter.
  22. # :
  23. #
  24. # Shamelessly stolen from other Nagios plugins.
  25. #
  26. PROGNAME=`basename $0`
  27. PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
  28. REVISION=`echo '$Revision: 71 $' | sed -e 's/[^0-9.]//g'`
  29. . $PROGPATH/utils.sh
  30. print_usage() {
  31. echo "Usage: $PROGNAME --help"
  32. echo "Usage: $PROGNAME --version"
  33. }
  34. print_help() {
  35. print_revision $PROGNAME $REVISION
  36. echo ""
  37. print_usage
  38. echo ""
  39. echo "Samba status check."
  40. echo ""
  41. support
  42. }
  43. # No command line arguments are required for this script. We accept only 2,
  44. # --help and --version. If more than 1 is passed in then we have an error
  45. # condition.
  46. if [ $# -gt 1 ]; then
  47. print_usage
  48. exit $STATE_UNKNOWN
  49. fi
  50. #
  51. # If we have arguments, process them.
  52. #
  53. exitstatus=$STATE_WARNING #default
  54. while test -n "$1"; do
  55. case "$1" in
  56. --help)
  57. print_help
  58. exit $STATE_OK
  59. ;;
  60. -h)
  61. print_help
  62. exit $STATE_OK
  63. ;;
  64. --version)
  65. print_revision $PROGNAME $REVISION
  66. exit $STATE_OK
  67. ;;
  68. -V)
  69. print_revision $PROGNAME $REVISION
  70. exit $STATE_OK
  71. ;;
  72. *)
  73. echo "Unknown argument: $1"
  74. print_usage
  75. exit $STATE_UNKNOWN
  76. ;;
  77. esac
  78. shift
  79. done
  80. #
  81. # No arguments. Let's kick this pig.
  82. #
  83. total_users=$(smbstatus -b | grep "^[0-9]" | wc -l)
  84. #
  85. # Ok, now let's grab a count of the files.
  86. #
  87. total_files=$(smbstatus | grep "^[0-9]" | wc -l)
  88. #
  89. # now for the dismount.
  90. #
  91. echo "Total Users:$total_users Total Files:$total_files"
  92. #
  93. # let Nagios know that everything is ok.
  94. #
  95. exit $STATE_OK