Fix bugs and improve output UI

- Fix hosts file existence check (was always false)
- Fix loop to use while+read to handle spaces in hostnames
- Filter empty lines from hosts file
- Fix error exits to use exit 1
- Show progress counter [n/total] per host
- Compact single-line output with colors
- Show [DRY RUN] prefix when -d is set
- Show per-host exit status (✓ ok / ✗ failed)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
floandClaude Sonnet 4.6 committed 2026-09-29 21:13:33 +02:00
1 parent f3c83317eb
commit 36c648d599
1 file changed
+30 -16
+30 -16
View File
@@ -84,17 +84,17 @@ then
echo "Error: group is not defined!" echo "Error: group is not defined!"
echo echo
usage usage
exit exit 1
fi fi
hosts="$confdir/$group" hosts="$confdir/$group"
if [ -z "$hosts" ] if [ ! -f "$hosts" ]
then then
echo "Error: hosts file $confdir/$group do not exists !" echo "Error: hosts file $confdir/$group does not exist!"
echo echo
usage usage
exit exit 1
fi fi
# see http://askubuntu.com/questions/506158/unable-to-initialize-frontend-dialog-when-using-ssh # see http://askubuntu.com/questions/506158/unable-to-initialize-frontend-dialog-when-using-ssh
@@ -105,24 +105,38 @@ FRONTEND="TERM=$TERM DEBIAN_FRONTEND=dialog"
if [ "$verbose" = true ] if [ "$verbose" = true ]
then then
echo "> will do :" echo "> will do :"
echo " grep -v '^ *#' < \"$hosts\" | while IFS= read -r line; do ssh -n -t \"\$line\" \"$FRONTEND $cmd\"; done" echo " grep -v '^ *#' \"$hosts\" | grep -v '^ *$' | while IFS= read -r line; do ssh -t \"\$line\" \"$FRONTEND $cmd\"; done"
fi fi
if [ "$dryRun" = false ] mapfile -t host_list < <(grep -v '^ *#' "$hosts" | grep -v '^ *$')
then total=${#host_list[@]}
for line in $(grep -v '^#' "$hosts")
do for i in "${!host_list[@]}"; do
echo -e "\e[34m------------------------------------------------------------\e[0m" line="${host_list[$i]}"
echo -e "\e[34m> \e[32m\"$cmd\" \e[34mon \e[32m$line\e[0m" n=$((i + 1))
echo -e "\e[34m> \e[33mssh -t \"$line\" \"$FRONTEND $cmd\"\e[0m"
echo -e "\e[34m------------------------------------------------------------\e[0m" if [ "$dryRun" = true ]; then
ssh -t "$line" "$FRONTEND $cmd" prefix="\e[33m[DRY RUN]\e[0m "
done else
prefix=""
fi fi
echo -e "${prefix}\e[34m[$n/$total]\e[0m \e[32m\"$cmd\"\e[0m \e[34mon\e[0m \e[32m$line\e[0m \e[34m→\e[0m \e[33mssh -t \"$line\" \"$FRONTEND $cmd\"\e[0m"
if [ "$dryRun" = false ]; then
ssh -t "$line" "$FRONTEND $cmd"
rc=$?
if [ $rc -eq 0 ]; then
echo -e "\e[32m✓ ok\e[0m"
else
echo -e "\e[31m✗ failed (exit $rc)\e[0m"
fi
fi
done
if [ "$verbose" = true ] if [ "$verbose" = true ]
then then
echo "> All done, bye." echo "> All done, bye."
fi fi
exit exit 0