Skip to content

Instantly share code, notes, and snippets.

@adujardin
Created September 23, 2022 08:42
Show Gist options
  • Save adujardin/b3572489c0d0c932d88ebffb9ef488a1 to your computer and use it in GitHub Desktop.
Save adujardin/b3572489c0d0c932d88ebffb9ef488a1 to your computer and use it in GitHub Desktop.
Script to reboot/run common command(s) to a list of linux machine through ssh
targets=(
192.168.1.83 # sl-u18-hlc1
192.168.2.253 # sl-nano-run5-46
192.168.3.220 # sl-tx2nx-run1-jp46
192.168.2.246 # sl-nx-run1-jp46
192.168.3.73 # sl-run-multicam
)
# all targets have the same user and password, this can be skipped if the ssh key is already registered
user="<user>"
pass="<password>" # security issue
for t in ${targets[@]}; do
#sshpass -p "${pass}" ssh-copy-id -i ~/.ssh/id_rsa.pub ${user}@${t} # register ssh key to avoid password prompt
sshpass -p "${pass}" ssh ${user}@${t} "echo ${pass} | sudo -S reboot"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment