Hello,
I've created a script to to see if any employees have more than 1 mac and then tie it to an extension attritubte. I've done an API get curl to pull information from a computer advance search I've made and then assign it to a list. The list then compares to another list that pulls google chrome emails that is tied to their work email.
The script is working on my end, but it does not post anything to the extension attribute. Is there anything in my script that is preventing to post? If a user has more than 1 mac, I just want it to say "yes" in the extension attribute.
Any input is appreciated! Thanks in advance to everyone.
user_list=()
##########################################################################################
# Curl command only retrieves the email addresses of this advanced search group.
# Command will api-GET the contents of the Advanced search
EmailList=$(/usr/bin/curl -X GET -s -H "Authorization: Bearer $api_Token" "$jssURL/JSSResource/advancedcomputersearches/id/149" -H "accept:text/xml" | xmllint --xpath "advanced_computer_search/computers/computer/Email_Address/text()" - | sort | uniq -c)
# Populate the array using awk and scans to see which emails appear twice or more. If a user appears more than once, this indicates user has multiple
while read -r email; do
user_list+=("$email")
done < <(awk '{if ($1 >= 2) print $2}' <<< "$EmailList")
##########################################################################################
####### Command will find the currently logged in google account #######
####### After pulling the currently logged in google account #######
####### It'll compare the email to $user_list to see if there is a duplicate mac. #######
currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
GoogleChromeAccounts=$(cat /Users/$currentUser/Library/Application\\ Support/Google/Chrome/Local\\ State | plutil -convert xml1 - -o - | grep -A1 user_name | grep @ | cut -d ">" -f 2 | cut -d "<" -f1)
readarray -t accounts_array <<< "$GoogleChromeAccounts"
##### Commands will search through duplicate list and compare to the logged in google account #####
for user in ${user_list[@]}; do
for gmail in ${accounts_array[@]}; do
if [[ " $user " == " $gmail " ]]; then
result="yes"
echo "<result>$result</result>"
exit
fi
done
done
