Skip to content

Instantly share code, notes, and snippets.

@mfurlend
Last active January 7, 2019 15:42
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 mfurlend/db74206df5a754ecbe212ce8a33f7337 to your computer and use it in GitHub Desktop.
Save mfurlend/db74206df5a754ecbe212ce8a33f7337 to your computer and use it in GitHub Desktop.
run command on each host
# run command on each host in /etc/hosts and print the output
# stop on failure (remove || break to continue on failure)
# use a pretty line break to delimit responses
# like this:
#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫hostname┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
eachhost () {
# ignore line 1 and 5 in /etc/hosts
for host in $(sed 1,5d /etc/hosts|awk '{print $2}')
do
(
mid=$(( ($(tput cols) / 2) - (($(echo $host | wc -m) + 2) /2 ))) && _hr=$(printf "%*s" $(( $(tput cols) - 2 ))) && echo -en ┏${_hr// /${2-━}}┓ && echo -e "\r\033[${mid}C┫${host}┣" && ssh $host "$*"
) || break
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment