Original post: nagios plugin webdav checkAccording to the good advice I have received I've made some modifications to the code:#!/bin/bash## check a WebDAV server# connect using a username and password and upload & delete a test file#Exit codesSTATE_OK=0STATE_WARNING=1STATE_CRITICAL=2STATE_UNKNOWN=3FILENAME=test_monitorFQFN=/tmp/$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 warning status[ $# -ne 4 ] && { echo Usage: $0 <hostname> <username> <password> <webdav_dir>; exit $STATE_UNKNOWN; }HOSTNAME=$1USERNAME=$2PASSWORD=$3WEBDAVDIR=$4BASEURL=http://$HOSTNAME/$WEBDAVDIR# create temp filetruncate -s 1M $FQFNif [ ! -f $FQFN ]; then    echo Test file not found!; exit $STATE_UNKNOWN;fi# check if curl is installedcommand -v curl >/dev/null 2>&1 || { echo >&2 Curl is not installed. Script cannot run.; exit $STATE_UNKNOWN; }function _curl {curl --fail -u $USERNAME:$PASSWORD $@}# connect to server and upload file_curl -s -T $FQFN $BASEURL/ > /dev/nullstatus=$?case $status in    0)        echo OK - File uploaded on WebDAV Server: $HOSTNAME        # remove test file        _curl -X DELETE $BASEURL/$FILENAME        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 $FQFN 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_UNKNOWNesacDo you have any more recommendations regarding syntax or script functionality?I am thinking about the removal of the test file. It is done if the upload is successful, but can it be assumed that if the upload is successful, the delete will be also? In my tests this has always been the case.Is there a chance for the delete command to fail? And should I modify the script somehow to accommodate for that?
Nagios plugin webdav check 2
bash;linux;plugin;shell;status monitoring
Thanks for incorporating the various suggestions and posting a new code review.  This is looking really excellent.  Some nits and answers to your concerns:creating a function for curling is good.  $@ is the right choice as well.  But it would be nice if the stuff within squiggly brackets was indented like:function _curl {    curl --fail -u $USERNAME:$PASSWORD $@}I would stick with deleting the temporary file each time so the test is complete each time.  One scenario that might happen would be for the disk to fill up, and so no WebDAV writes are possible, but your test succeeds because it has the space of the existing file to work with or maybe there's code so it doesn't rewrite the file for performance reasons.  Either way leads to a false negative check which is best avoided.It would be more thorough and nice to check the return value from the delete as well.  Doing this with a nested case statement could get unwieldy and certainly duplicates a lot of code.  If you can turn the case statement into its own function that could bucket the return values for creates or deletes that might be easier to maintain.  There might be other nagios checks where you want to check the output of curl similarly which would be good to keep in mind when designing this curl return evaluator.Aren't you linking to the wrong prior question?  nagios plugin webdav check was how I got here.  :)