Last active
October 1, 2020 13:02
-
-
Save marek-saji/2e40df4fe480ce99e6c3f0f417eb3944 to your computer and use it in GitHub Desktop.
df across hosts
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
MY_HOSTS="list of hosts I own" | |
_dff () | |
{ | |
local df | |
df="$( | |
TAIL=+1 | |
{ | |
echo / | |
echo /tmp | |
echo /home | |
find /media/ "/media/${USER}" -mindepth 1 -maxdepth 1 -type 'd' -exec sh -c 'mountpoint -q "$1" && echo "$1"' _ {} \; 2>/dev/null | |
} | | |
while read -r MP | |
do | |
df -h "$MP" | tail -n${TAIL} | |
TAIL=+2 | |
done | |
)" | |
echo "${df}" | head -n1 | |
echo "${df}" | tail -n+2 | | |
sort --key=6 | uniq | | |
GREP_COLOR=1 grep -E --color=always '^.*/$|$' | |
} | |
dff () | |
{ | |
_dff | |
# shellcheck disable=SC2043 | |
for HOST in $MY_HOSTS | |
do | |
if [ "${HOST}" != "${HOSTNAME}" ] | |
then | |
echo | |
printf "Checking %s… " "${HOST}" | |
# shellcheck disable=SC2029 | |
if ! ssh -o ConnectTimeout=3 "${HOST}" "printf \"\\r$( tput el 2>/dev/null ; tput smul 2>/dev/null )${HOST}$( tput sgr0 2>/dev/null )\\n\"; $( type _dff | tail -n+2 ); _dff" 2>/dev/null | |
then | |
echo "failed to connect" | |
fi | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment