#!/bin/bash print_help() { echo "Usage: $0 -h -s " echo "Checks if the specified NFS shares are exported on the given host." echo "" echo "-h The IP address or hostname of the NFS server." echo "-s A comma-separated list of NFS shares to check. For example: '/mnt/test,/mnt/export'" echo "" echo "You can list the exported shares on an NFS server using the command 'showmount -e '" echo "This script assumes that 'showmount' is installed on the system where it is run." exit 1 } if ! command -v showmount &> /dev/null; then echo "UNKNOWN - 'showmount' is not installed" exit 3 fi if [ "$#" -ne 4 ] || [ "$1" == "--help" ]; then print_help fi while getopts "h:s:" opt; do case ${opt} in h ) host=$OPTARG ;; s ) shares=$OPTARG ;; \? ) print_help ;; esac done share_count=0 all_ok=true IFS=',' read -r -a share_array <<< "$shares" for share in "${share_array[@]}"; do output=$(showmount -e $host | grep $share) if [[ $output != *"$share"* ]]; then echo "CRITICAL - $share is not exported on $host" exit 2 fi share_count=$((share_count+1)) done if $all_ok; then echo "OK - All $share_count shares are exported on $host | share_count=$share_count" fi exit 0