Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Exit codes
- STATE_OK=0
- STATE_WARNING=1
- STATE_CRITICAL=2
- STATE_UNKNOWN=3
- FILENAME=/tmp/test_monitor
- FILE=test_monitor
- HOSTNAME=$1
- USERNAME=$2
- PASSWORD=$3
- WEBDAVDIR=$4
- # Verify the type of input and number of values
- # Display an error message if the (input) is not correct
- # Exit the shell script with a status of 1 using exit 1 command.
- [ $# -ne 4 ] && { echo "Usage: $0 <hostname> <username> <password> <webdav_dir>"; exit 1; }
- # create temp file
- truncate -s 1M /tmp/test_monitor
- # connect to server and upload file
- curl --fail -T $FILENAME -u $USERNAME:$PASSWORD http://$HOSTNAME/$WEBDAVDIR/
- status=$?
- case $status in
- 0)
- echo "OK - File uploaded on WebDAV Server: $HOSTNAME"
- # remove test file
- curl --fail -X DELETE -u $USERNAME:$PASSWORD http://$HOSTNAME/$WEBDAVDIR/$FILE
- exit $STATE_OK
- ;;
- 1)
- echo "CRITICAL - Cannot upload file on $HOSTNAME"
- exit $STATE_CRITICAL
- ;;
- 6)
- echo "CRITICAL - Could not resolve host $HOSTNAME"
- exit $STATE_CRITICAL
- ;;
- 26)
- echo "CRITICAL - Cannot open $FILENAME for upload"
- exit $STATE_CRITICAL
- ;;
- 22)
- echo "CRITICAL - The requested URL returned error"
- exit $STATE_CRITICAL
- ;;
- 127)
- echo "CRITICAL - Command not found"
- exit $STATE_CRITICAL
- ;;
- *)
- echo "UNKNOWN - "
- exit $STATE_UNKNOWN
- esac
- # create temp file
- truncate -s 1M /tmp/test_monitor
- truncate -s 1M $FILENAME
- # Verify the type of input and number of values
- # Display an error message if the (input) is not correct
- # Exit the shell script with a status of 1 using exit 1 command.
- [ $# -ne 4 ] && { echo "Usage: $0 <hostname> <username> <password> <webdav_dir>"; exit 1; }
- HOSTNAME=$1
- USERNAME=$2
- PASSWORD=$3
- WEBDAVDIR=$4
- FILENAME=/tmp/test_monitor
- FILE=test_monitor
- FILE=test_monitor
- FILENAME=/tmp/$FILE
- FILENAME=test_monitor
- FQFN=/tmp/$FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement