Skip to content

Instantly share code, notes, and snippets.

@n-st
Last active August 29, 2015 13:57
Show Gist options
  • Save n-st/9689820 to your computer and use it in GitHub Desktop.
Save n-st/9689820 to your computer and use it in GitHub Desktop.
Quickly update multiple remote Debian/Ubuntu systems.
#!/bin/bash
# Uncomment the next line to start any pending updates automatically:
#yes="--yes"
for host in host1 host2 # etc.
do
echo -e "\e[0;33m$host\e[0m"
ssh "$host" -t "
# Update package index if it's older than 24 hours.
test \$((\$(date +%s) - \$(stat -c %Y /var/cache/apt))) -gt $((24*60*60)) && sudo apt-get update;
# Simulate an update to check if something would be installed. If so, start a real update.
apt-get -s dist-upgrade | grep -E '[1-9]' -q && sudo apt-get dist-upgrade $yes"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment