Extension Attribute not displaying results in jamf pro

AlexHoffman
New Contributor III

Most of my scripting experience is in Powershell and not shell scripting. I'm trying to create an extension attribute in JAMF Pro that checks if the Jamf Connect user is logged into a device. I can get the script to work in Terminal and spit out the information I want. However, after waiting a day, it's still not populating the results in Jamf Pro under the computer record. I'm sure I'm missing some command that sends the data to Jamf, but not sure what that would be. 

jamfConnectStateLocation=/Users/$currentUser/Library/Preferences/com.jamf.connect.state.plist
CurrentPassword=$(defaults read com.jamf.connect.state PasswordCurrent)
if [[ $CurrentPassword == 1 ]]; then
    echo “User is logged in”
elif [[ $CurrentPassword == 0 ]]; then
    echo “User is not logged in”
fi

The above is the script that works in terminal. I've tried adding echo "<result>$CurrentPassword</result>" on the end, but that spits back an error that result is not a recognized command. 

I've also tried changing the script to be the following

jamfConnectStateLocation=/Users/$currentUser/Library/Preferences/com.jamf.connect.state.plist
CurrentPassword=$(defaults read com.jamf.connect.state PasswordCurrent)
if [[ $CurrentPassword == 1 ]]; then
    RESULT=“User is logged in”
elif [[ $CurrentPassword == 0 ]]; then
    RESULT=“User is not logged in”
fi

Echo "<result>${RESULT}</result>"

But this just spits out an error message and doesn't return anything. Any help would be greatly appreciated! 

1 ACCEPTED SOLUTION

Hello @AlexHoffman 

I just tried this on my test server and it is working, had to clean up the script a little to get it to work.

once you update your Extension attribute you should be able to run sudo jamf recon on your test machine to see the results right away.

#!/bin/bash
currentUser=$(/usr/bin/stat -f "%Su" /dev/console)
jamfConnectStateLocation="/Users/$currentUser/Library/Preferences/com.jamf.connect.state.plist"
CurrentPassword=$(defaults read ${jamfConnectStateLocation} PasswordCurrent)
if [[ $CurrentPassword == 1 ]]; then
    RESULT='User is logged in'
elif [[ $CurrentPassword == 0 ]]; then
    RESULT='User is not logged in'
fi

echo "<result>$RESULT</result>"

 

Screen Shot 2022-05-13 at 9.22.48 AM.png

View solution in original post

4 REPLIES 4

gabe2385
Contributor

Hello @AlexHoffman 

not sure if you added a interpreter to run the script like #!/bin/bash or #!/bin/zsh, also the last line of Echo should be lower case echo 

AlexHoffman
New Contributor III

I have it set to #!/bin/bash

Hello @AlexHoffman 

I just tried this on my test server and it is working, had to clean up the script a little to get it to work.

once you update your Extension attribute you should be able to run sudo jamf recon on your test machine to see the results right away.

#!/bin/bash
currentUser=$(/usr/bin/stat -f "%Su" /dev/console)
jamfConnectStateLocation="/Users/$currentUser/Library/Preferences/com.jamf.connect.state.plist"
CurrentPassword=$(defaults read ${jamfConnectStateLocation} PasswordCurrent)
if [[ $CurrentPassword == 1 ]]; then
    RESULT='User is logged in'
elif [[ $CurrentPassword == 0 ]]; then
    RESULT='User is not logged in'
fi

echo "<result>$RESULT</result>"

 

Screen Shot 2022-05-13 at 9.22.48 AM.png

AlexHoffman
New Contributor III

Thank you!!!!