Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #!/bin/bash
  2. #Exit codes
  3. STATE_OK=0
  4. STATE_WARNING=1
  5. STATE_CRITICAL=2
  6. STATE_UNKNOWN=3
  7.  
  8. FILENAME=/tmp/test_monitor
  9. FILE=test_monitor
  10. HOSTNAME=$1
  11. USERNAME=$2
  12. PASSWORD=$3
  13. WEBDAVDIR=$4
  14.  
  15. # Verify the type of input and number of values
  16. # Display an error message if the (input) is not correct
  17. # Exit the shell script with a status of 1 using exit 1 command.
  18. [ $# -ne 4 ] && { echo "Usage: $0 <hostname> <username> <password> <webdav_dir>"; exit 1; }
  19.  
  20. # create temp file
  21. truncate -s 1M /tmp/test_monitor
  22.  
  23. # connect to server and upload file
  24. curl --fail -T $FILENAME -u $USERNAME:$PASSWORD http://$HOSTNAME/$WEBDAVDIR/
  25.  
  26. status=$?
  27. case $status in
  28. 0)
  29. echo "OK - File uploaded on WebDAV Server: $HOSTNAME"
  30. # remove test file
  31. curl --fail -X DELETE -u $USERNAME:$PASSWORD http://$HOSTNAME/$WEBDAVDIR/$FILE
  32. exit $STATE_OK
  33. ;;
  34. 1)
  35. echo "CRITICAL - Cannot upload file on $HOSTNAME"
  36. exit $STATE_CRITICAL
  37. ;;
  38. 6)
  39. echo "CRITICAL - Could not resolve host $HOSTNAME"
  40. exit $STATE_CRITICAL
  41. ;;
  42. 26)
  43. echo "CRITICAL - Cannot open $FILENAME for upload"
  44. exit $STATE_CRITICAL
  45. ;;
  46. 22)
  47. echo "CRITICAL - The requested URL returned error"
  48. exit $STATE_CRITICAL
  49. ;;
  50. 127)
  51. echo "CRITICAL - Command not found"
  52. exit $STATE_CRITICAL
  53. ;;
  54. *)
  55. echo "UNKNOWN - "
  56. exit $STATE_UNKNOWN
  57. esac
  58.  
  59. # create temp file
  60. truncate -s 1M /tmp/test_monitor
  61.  
  62. truncate -s 1M $FILENAME
  63.  
  64. # Verify the type of input and number of values
  65. # Display an error message if the (input) is not correct
  66. # Exit the shell script with a status of 1 using exit 1 command.
  67. [ $# -ne 4 ] && { echo "Usage: $0 <hostname> <username> <password> <webdav_dir>"; exit 1; }
  68.  
  69. HOSTNAME=$1
  70. USERNAME=$2
  71. PASSWORD=$3
  72. WEBDAVDIR=$4
  73.  
  74. FILENAME=/tmp/test_monitor
  75. FILE=test_monitor
  76.  
  77. FILE=test_monitor
  78. FILENAME=/tmp/$FILE
  79.  
  80. FILENAME=test_monitor
  81. FQFN=/tmp/$FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement