#!/bin/bash
# Needs jq package installed

sudo -u apache php occ user:list > /tmp/list_user_06.txt

while read line; do
  echo "$line"
  uid=`echo "${line:2}" | cut -d":" -f1`
  #echo "$uid"
  info_user=`sudo -u apache php occ user:info "$uid" --output=json`
  #echo $info_user
  homePath=`echo $info_user | jq -r '.user_directory'`
  #echo $homePath
  if [ -d $homePath ]; then
    du_homePath=`du -s $homePath | cut -f 1`
    wc_homePath=`find $homePath -type f | wc -l`
  else
    continue
  fi
  if (( $wc_homePath > 30000 )); then
    if [ $homePath != "/data/pbarriat" ]; then
      echo "Remove files $homePath/files/* for user $uid"
      #rm -rf $homePath
      #sudo -u apache php occ files:scan -vvv $uid --home-only 
    fi
  fi
  #exit
done < /tmp/list_user_06.txt

#sudo -u apache php occ files:scan -vvv --all --home-only
