I fully agree with jhwilliams.
If you have a lot of machines to connect to, you might wish to do the installations in parallel, instead of one after the other. Something like the following should prove useful:
Code:
#!/bin/bash
# File containing hostnames for all the servers; one per line.
serverlist=~/.server-list
[ -r "$serverlist" ] || exit 1
# Create a safe, autodeleted temporary directory
work=$(mktemp -d) || exit $?
trap "rm -rf '$work'" EXIT
# List of hosts to connect to
hosts=()
while read host dummy ; do
# Ignore comments
host="${host%%;*}"
host="${host%%#*}"
host="${host%%/*}"
[ -n "$host" ] || continue
# Add host to hosts used
hosts=("${hosts[@]}" "$host")
done < "$serverlist" || exit $?
# None?
[ ${#hosts[@]} -gt 0 ] || exit 0
# Run remote commands in parallel on each host.
for host in "${hosts[@]}" ; do
( exec </dev/null >"$work/$host.out" 2>"$work/$host.err"
echo -n "Started "
date
ssh "$host" "$@" && echo "[OK]" || echo "[Error $?]"
echo -n "Finished "
date
) &
done
# Wait for all to complete
wait
# Output the summary of all commands
for host in "${hosts[@]}" ; do
echo "Output from $host:"
sed -e 's|^|\t|' "$work/$host.out"
echo ""
if [ -s "$work/$host.err" ]; then
echo "Errors from $host:"
sed -e 's|^|\t|' "$work/$host.err"
else
echo "No error messages."
fi
echo ""
echo "========================================"
fi