Last active
February 6, 2019 18:12
-
-
Save hyukishi/775f8cff5361b0b15f6e49f8ac6aad56 to your computer and use it in GitHub Desktop.
Perform linux maintenance across multiple boxes with ease using screens
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 | |
# linuxmaintenance.sh | |
# Authored Sep 7 2018 by Jim | |
# Optimized Jan 4 2019 by Jeffery Grantham | |
# You must have a file named hosts.txt containing each hostname or FDQN for the boxes of which maintenance will be performed | |
# Hosts/FQDNs must have 1 listed per line for the script to execute properly | |
# run-updates script must be on target boxes and included in the PATH for the root user | |
# Checking if screen is installed. If not, apt will install it. | |
if [[ $(which screen) != "/usr/bin/screen" ]]; then | |
apt install screen -y | |
fi | |
# Proceeding with screen creation for each host | |
for HOST in `cat ~/bin/hosts.txt` | |
do | |
echo $HOST | |
screen -d -m -S $HOST ssh root@$HOST | |
screen -r $HOST -p0 -X stuff "$(echo -ne '\001\013') { run-updates.sh && exit ; } $(echo -ne '\015')" | |
done | |
# Resume each screen in sequential order in the same window. E.g. exit ; screen -r (nextscreen) | |
for line in `screen -ls | grep Detached | awk '{print $1}'` | |
do `screen -r $line` | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment