iCloud Username

gary_owen
New Contributor II

I am using the following script as a EA to pull up the users iCloud account name, this works fine but if the machine hasn't updated inventory, or, if the user hasn't created a iCloud account then its just blank, I would like the script to report None if the iCloud account doesn't exist, could anyone modify the script to accommodate this ?

#!/bin/bash for user in $(ls /Users/ | grep -v Shared); do if [ -d "/Users/$user/Library/Application Support/iCloud/Accounts" ]; then Accts=$(find "/Users/$user/Library/Application Support/iCloud/Accounts" | grep '@' | awk -F'/' '{print $NF}') iCloudAccts+=(${user}: ${Accts}) fi done echo "<result>$(printf '%s ' "${iCloudAccts[@]}")</result>"
2 REPLIES 2

DBrowning
Valued Contributor II

@gary.owen Try this:

#!/bin/bash

for user in $(ls /Users/ | grep -v Shared); do
    if [ -d "/Users/$user/Library/Application Support/iCloud/Accounts" ]; then
        Accts=$(find "/Users/$user/Library/Application Support/iCloud/Accounts" | grep '@' | awk -F'/' '{print $NF}')
        iCloudAccts+=(${user}: ${Accts})
    else
        Accts="None"
        iCloudAccts+=(${user}: ${Accts})
    fi
done

echo "<result>$(printf '%s
' "${iCloudAccts[@]}")</result>"

gary_owen
New Contributor II

Thats great, Thanks