-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnextcloud_user_export.sh
More file actions
executable file
·41 lines (29 loc) · 1.32 KB
/
nextcloud_user_export.sh
File metadata and controls
executable file
·41 lines (29 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Run nextcloud occ command to get user list
user_list=$(sudo -u www-data php /var/www/nextcloud/occ user:list --output=json)
# Print the user list content for verification
echo "$user_list"
# Create an empty array to store user details
user_details=()
# Extract usernames and nicknames using jq
usernames=$(echo "$user_list" | jq -r 'to_entries[] | "\(.key):\(.value)"')
# Fetch user information for each username
while IFS= read -r entry; do
username=$(echo "$entry" | cut -d ':' -f1)
if [ -n "$username" ]; then
echo "Fetching info for user: $username"
# Get user information using user:info for each user
info=$(sudo -u www-data php /var/www/nextcloud/occ user:info "$username" --output=json)
# Check if the info is not empty and doesn't contain an error message
if [ -n "$info" ] && ! echo "$info" | grep -q "user not found"; then
user_details+=("$info")
else
echo "Error fetching info for user: $username"
fi
fi
done <<< "$usernames"
# Convert the user details array to JSON format
user_details_json=$(printf '%s\n' "${user_details[@]}" | jq -s '.')
# Save the retrieved user details directly to a file
echo "$user_details_json" > nextcloud_user_info.json
echo "User details exported to nextcloud_user_info.json"