A bash script to run apt update && apt upgrade in parallel across multiple cluster nodes via SSH.
This script performs system updates on all specified nodes simultaneously, collecting logs and providing a summary of successes and failures.
- SSH key-based authentication configured to all target nodes
- User must have passwordless
sudoprivileges on all target nodes - All nodes must be reachable by hostname (via
/etc/hostsor DNS)
Edit the script to customize:
# List of nodes to update
NODES=(
"node"
"node-1"
"node-2"
"node-3"
)
# SSH username
USER="<USER_NAME>"-
Make the script executable:
chmod +x update_sys.sh
-
Run the script:
./update_sys.sh
Starting update on node...
Starting update on node-1...
Starting update on node-2...
Starting update on node-3...
node-1 complete.
node complete.
node-3 complete.
node-2 FAILED! Check /tmp/cluster-update-12345/node-2.log
========== SUMMARY ==========
Succeeded: 3
Failed: 1
Failed nodes:
node-2
Logs saved in: /tmp/cluster-update-12345
- Creates a temporary log directory (
/tmp/cluster-update-<PID>) - Spawns parallel SSH connections to all nodes
- Runs
sudo apt update && sudo apt upgrade -yon each node - Captures output to individual log files per node
- Tracks success/failure status
- Waits for all updates to complete
- Displays summary with pass/fail counts
Logs are stored in /tmp/cluster-update-<PID>/:
| File | Contents |
|---|---|
<node>.log |
Full apt output for each node |
success |
List of nodes that updated successfully |
failed |
List of nodes that failed |
- Updates run in parallel, so output may be interleaved
- The script waits for all nodes to complete before showing the summary
- Log directory persists after script completion for troubleshooting
- Each run creates a new log directory (using PID to avoid conflicts)
SSH connection fails:
- Verify SSH key authentication:
ssh user@node "echo OK" - Check that the node hostname resolves correctly
Sudo password prompt hangs:
- Configure passwordless sudo for apt on target nodes:
echo "username ALL=(ALL) NOPASSWD: /usr/bin/apt" | sudo tee /etc/sudoers.d/apt-update
Package lock errors:
- Another apt process may be running on the node
- Check the node's log file for details
- v1.0 - Initial release