diff --git a/System_Essentials/server_reboot.sh b/System_Essentials/server_reboot.sh index 3ca5434..44b4f30 100755 --- a/System_Essentials/server_reboot.sh +++ b/System_Essentials/server_reboot.sh @@ -166,8 +166,11 @@ if [[ "$SHOW_STATUS" == true ]]; then log " mover: not running" if command -v virsh >/dev/null 2>&1; then - VM_COUNT=$(virsh list --name 2>/dev/null | grep -c "." || echo 0) - [[ "$VM_COUNT" -gt 0 ]] && \ + # No "|| echo 0" here: grep -c prints 0 on no match AND exits 1, so the fallback fires as + # well and the variable becomes two lines. "$VM_COUNT" -gt 0 then dies with an arithmetic + # syntax error — on the no-VMs path, which is the normal one. + VM_COUNT=$(virsh list --name 2>/dev/null | grep -c "." || true) + [[ "${VM_COUNT:-0}" -gt 0 ]] && \ warn " VMs: $VM_COUNT running — will be gracefully shut down" || \ log " VMs: none running" fi @@ -207,7 +210,7 @@ if [[ -n "${EMBY_URL:-}" ]] && [[ -n "${EMBY_API_KEY:-}" ]]; then ACTIVE_STREAMS=$(curl -sf --max-time 5 \ -H "X-Emby-Token: $EMBY_API_KEY" \ "${EMBY_URL}/Sessions" 2>/dev/null | \ - grep -c "NowPlayingItem" 2>/dev/null || echo 0) + grep -c "NowPlayingItem" 2>/dev/null || true) ACTIVE_STREAMS="${ACTIVE_STREAMS//[^0-9]/}" if [[ "${ACTIVE_STREAMS:-0}" -gt 0 ]]; then warn "$ACTIVE_STREAMS active Emby stream(s) — will be interrupted" @@ -215,11 +218,11 @@ if [[ -n "${EMBY_URL:-}" ]] && [[ -n "${EMBY_API_KEY:-}" ]]; then fi fi -CONTAINER_COUNT=$(docker ps -q 2>/dev/null | wc -l || echo 0) +CONTAINER_COUNT=$(docker ps -q 2>/dev/null | wc -l) log "$ICON_CONTAINERS Docker: ${CONTAINER_COUNT} container(s) running" if is_vm_manager_enabled && command -v virsh >/dev/null 2>&1; then - VM_COUNT=$(virsh list --name 2>/dev/null | grep -c "." || echo 0) + VM_COUNT=$(virsh list --name 2>/dev/null | grep -c "." || true) log "$ICON_GEAR VMs: ${VM_COUNT} running" fi