Last active
August 29, 2024 16:00
-
-
Save cinsk/840ed553905cb6e8f0ae to your computer and use it in GitHub Desktop.
Check if NFS mounted directory is stale
This file contains 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
#!/bin/bash | |
PATH=/bin:/usr/bin:/usr/local/bin | |
check-nfs () { | |
local TMPFILE=/tmp/checknfs.$$ RET=0 ORPHAN SUBSHELLPID | |
if [ "$#" -eq 0 ]; then | |
cat<<EOF | |
usage: check-nfs NFS-DIRECTORY... | |
Check if accessing any of NFS-DIRECTORY failed | |
EOF | |
return 1 | |
fi | |
while [ -n "$1" ]; do | |
read -t 1 < <(echo $BASHPID >"$TMPFILE"; stat -t "$1" 2>/dev/null) | |
if [ "$?" -gt 128 ]; then | |
#echo "error: $1" | |
ORPHAN=$(cat $TMPFILE) | |
SUBSHELLPID=$(ps --ppid $ORPHAN -o pid=) | |
[ -n "$SUBSHELLPID" ] && kill -9 $SUBSHELLPID | |
kill -9 $ORPHAN | |
RET=1 | |
fi | |
shift | |
rm -f $TMPFILE | |
done | |
return "$RET" | |
} | |
check-nfs "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found a link to here on stackoverflow and made this for my crontab to execute every minute: