05_remove_inactive_users.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. # Needs jq package installed
  3. sudo -u apache php occ user:list > /tmp/list_user.txt
  4. while read line; do
  5. echo "$line"
  6. uid=`echo "${line:2}" | cut -d":" -f1`
  7. #echo "$uid"
  8. settings_user=`sudo -u apache php occ user:setting "$uid" --output=json`
  9. #echo $settings_user
  10. info_user=`sudo -u apache php occ user:info "$uid" --output=json`
  11. #echo $info_user
  12. uldap=`echo $settings_user | jq -r '.user_ldap.uid'`
  13. #echo $uldap
  14. last_seen=`echo $info_user | jq -r '.last_seen'`
  15. #echo $last_seen
  16. if [ $last_seen = "1970-01-01T00:00:00+00:00" ]; then
  17. homePath=`echo $info_user | jq -r '.user_directory'`
  18. if [ -d $homePath ]; then
  19. du_homePath=`du -s $homePath | cut -f 1`
  20. else
  21. du_homePath=0
  22. fi
  23. if (( $du_homePath == 0 )); then
  24. #echo "Remove user $uldap ($uid)"
  25. #sudo -u apache php occ user:delete $uid
  26. #
  27. if [ -d $homePath ]; then
  28. echo "Remove empty folder for user $uldap ($uid)"
  29. rm -rf $homePath
  30. fi
  31. fi
  32. fi
  33. #exit
  34. done < /tmp/list_user.txt