Last active
January 20, 2022 15:26
-
-
Save ucyo/b58fc1f3537ca0d8a48ff32bf0a70486 to your computer and use it in GitHub Desktop.
Check a list of mount points and send an email if the mount is not active
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -Ee # fail script, if single command fails | |
| set -u # unset variables are treated as errors | |
| set -f # no filename extension | |
| set -o pipefail # if a subcommand from a pipe fails, the whole pipe fails | |
| trap cleanup SIGINT SIGTERM ERR EXIT # execute cleanup function at following signals | |
| SOURCE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) # location of script | |
| cleanup() { | |
| trap - SIGINT SIGTERM ERR EXIT | |
| # script cleanup here | |
| } | |
| SENDER="Administration [$(hostname)]" | |
| DESTINATION="<E-MAIL-ADRESS>" | |
| CHECKPOINTS=( | |
| "/mnt/directory1" | |
| "/mnt/directory2" | |
| ) | |
| for mount_check in "${CHECKPOINTS[@]}" | |
| do | |
| if ! mountpoint -q "${mount_check}" | |
| then | |
| sendmail "-F ${SENDER}" "${DESTINATION}" <<< "${mount_check} failed" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment