57 lines
1.3 KiB
Bash
Executable File
57 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
print_help() {
|
|
echo "Usage: $0 -h <host> -s <exports>"
|
|
echo "Checks if the specified NFS exports are exported on the given host."
|
|
echo ""
|
|
echo "-h The IP address or hostname of the NFS server."
|
|
echo "-e A comma-separated list of NFS exports 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 <host>'"
|
|
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. Try installing 'nfs-common'"
|
|
exit 3
|
|
fi
|
|
|
|
if [ "$#" -ne 4 ] || [ "$1" == "--help" ]; then
|
|
print_help
|
|
fi
|
|
|
|
while getopts "h:e:" opt; do
|
|
case ${opt} in
|
|
h )
|
|
host=$OPTARG
|
|
;;
|
|
e )
|
|
exports=$OPTARG
|
|
;;
|
|
\? )
|
|
print_help
|
|
;;
|
|
esac
|
|
done
|
|
|
|
share_count=0
|
|
all_ok=true
|
|
|
|
IFS=',' read -r -a share_array <<< "$exports"
|
|
|
|
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 - $share_count NFS exports on $host | share_count=$share_count"
|
|
fi
|
|
|
|
exit 0
|