Skip to content

Instantly share code, notes, and snippets.

@marek-saji
Last active October 1, 2020 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marek-saji/2e40df4fe480ce99e6c3f0f417eb3944 to your computer and use it in GitHub Desktop.
Save marek-saji/2e40df4fe480ce99e6c3f0f417eb3944 to your computer and use it in GitHub Desktop.
df across hosts
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