Posted on 02-13-2024 04:50 AM
I'm trying to establish the last time a user actually logged in to their laptop. I have, therefore, created a Computer Extension that runs a simple script that is supposed to display a String result in User and Location:
#!/bin/zsh
/usr/bin/last -1 -t console | <result>/usr/bin/awk '{print $4, $5, $6}'
I added the Computer Extension to the Configuration Profile under ALLOWED EXTENSIONS but nothing ever seems to be displayed. How are Computer Extensions actually meant to work, i.e. how am I meant to actually see the data that is gathered???
Solved! Go to Solution.
Posted on 02-13-2024 05:07 AM
@VL You need to use the proper form of the result tag to bracket what your EA returns, e.g.
#!/bin/sh
result=$(/usr/bin/last -1 -t console | /usr/bin/awk '{print $4, $5, $6}')
echo "<result>$result</result>"
Posted on 02-13-2024 05:09 AM
Your formatting is off, an EA needs the <results> tag for Jamf to know what do report from the script.
Something like the script below will work, just tinker with what you want the results to be. This script will report the last 3 login events, and could be adjusted to the last login event and grep or awk to filter beyond that.
#!/bin/bash
# Get the first 3 login events
last_entries=$(last -3)
# Display the information
if [ -n "$last_entries" ]; then
echo "First 3 login events:"
echo "<result>$last_entries</result>"
else
echo "<result>No recent login information found.</result>"
fi
Posted on 02-13-2024 04:56 AM
Are you trying to deploy an Extension Attribute? If so, the command is not valid, Jamf also reports when a user logs in within the devices inventory record granted you cannot make searches for this data.
Posted on 02-13-2024 04:57 AM
OK, I got the Configuration Profile > Extensions mixed up with Computer Extension, but still not seeing any data gathered.
Posted on 02-13-2024 05:09 AM
Your formatting is off, an EA needs the <results> tag for Jamf to know what do report from the script.
Something like the script below will work, just tinker with what you want the results to be. This script will report the last 3 login events, and could be adjusted to the last login event and grep or awk to filter beyond that.
#!/bin/bash
# Get the first 3 login events
last_entries=$(last -3)
# Display the information
if [ -n "$last_entries" ]; then
echo "First 3 login events:"
echo "<result>$last_entries</result>"
else
echo "<result>No recent login information found.</result>"
fi
Posted on 02-13-2024 05:07 AM
@VL You need to use the proper form of the result tag to bracket what your EA returns, e.g.
#!/bin/sh
result=$(/usr/bin/last -1 -t console | /usr/bin/awk '{print $4, $5, $6}')
echo "<result>$result</result>"