Last active
September 2, 2021 09:54
-
-
Save rzrbld/bc32a9d4f443383d829c to your computer and use it in GitHub Desktop.
bash script to ssh multiple servers in a loop
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
#!/bin/bash | |
for server in $(cat hosts.txt); do | |
IP=`echo "$server" | awk 'BEGIN {RS = "|"}; END {print $1}'`; | |
HOST=`echo "$server" | awk 'BEGIN {FS = "|"}; END {print $1}'`; | |
USER=`echo $HOST | sed 's/tst-centos-//g;s/\-.//g;'`; | |
echo "$HOST($IP)" | |
echo $USER | |
ssh -nt $USER@$IP -i ssh/$USER 'sudo yum -y remove test-pkg && sudo rm -rf /var/lib/test' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment