Skip to content

Instantly share code, notes, and snippets.

@brwyatt
Created September 2, 2016 20:34
Show Gist options
  • Save brwyatt/b725d52a8ea1328e57a55f151dbb7729 to your computer and use it in GitHub Desktop.
Save brwyatt/b725d52a8ea1328e57a55f151dbb7729 to your computer and use it in GitHub Desktop.
#!/bin/bash
servers=()
unset input
read -p "Server ${#servers[@]}: " input
while [ ${#servers[@]} -eq 0 ] || [[ "x${input}" != "x" ]]; do
if [[ "x${input}" != "x" ]]; then
servers=("${servers[@]}" $input)
fi
unset input
read -p "Server ${#servers[@]}: " input
done
read -p 'Username: ' user
read -s -p 'Password: ' password
echo
read -p 'Command: ' cmd
for server in ${servers[@]}; do
echo "**** Running '${cmd}' on '${server}' as '${user}'..."
sshpass -p"${password}" ssh "${user}"@"${server}" "${cmd}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment