2024-06-22 19:58:00 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
print_help() {
|
2024-06-22 20:02:36 -06:00
|
|
|
echo "Usage: $0 -h <host> -s <shares>"
|
2024-06-22 19:58:00 -06:00
|
|
|
echo "Checks if the specified NFS shares are exported on the given host."
|
|
|
|
echo ""
|
2024-06-22 20:02:36 -06:00
|
|
|
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'"
|
2024-06-22 19:58:00 -06:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-06-22 20:02:36 -06:00
|
|
|
if [ "$#" -ne 4 ] || [ "$1" == "-help" ] || [ "$1" == "--help" ]; then
|
2024-06-22 19:58:00 -06:00
|
|
|
print_help
|
|
|
|
fi
|
|
|
|
|
2024-06-22 20:02:36 -06:00
|
|
|
while getopts "h:s:" opt; do
|
|
|
|
case ${opt} in
|
|
|
|
h )
|
|
|
|
host=$OPTARG
|
|
|
|
;;
|
|
|
|
s )
|
|
|
|
shares=$OPTARG
|
|
|
|
;;
|
|
|
|
\? )
|
|
|
|
print_help
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-06-22 19:58:00 -06:00
|
|
|
share_count=0
|
2024-06-22 20:02:36 -06:00
|
|
|
all_ok=true
|
2024-06-22 19:58:00 -06:00
|
|
|
|
|
|
|
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 specified shares are exported on $host | share_count=$share_count"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|