#!/bin/bash
echo "=== PAVON USER DETAILS ==="
sudo -u apache php /var/www/owncloud/occ user:list-groups pavon 2>&1
echo
echo "=== ALL USERS WITH GROUPS ==="
for u in $(sudo -u apache php /var/www/owncloud/occ user:list 2>&1 | awk -F': ' '{print $2}' | tr -d ' '); do
    [ -z "$u" ] && continue
    grps=$(sudo -u apache php /var/www/owncloud/occ user:list-groups "$u" 2>&1 | grep -E '^\s+-' | awk -F'- ' '{print $2}' | paste -sd, -)
    echo "$u: ${grps:-(no groups)}"
done
