How are computer extensions actually meant to work

VL
New Contributor III

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???

2 ACCEPTED SOLUTIONS

sdagley
Esteemed Contributor II

@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>"

View solution in original post

AJPinto
Esteemed Contributor

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

 

View solution in original post

4 REPLIES 4

AJPinto
Esteemed Contributor

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.

VL
New Contributor III

OK, I got the Configuration Profile > Extensions mixed up with Computer Extension, but still not seeing any data gathered.

AJPinto
Esteemed Contributor

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

 

sdagley
Esteemed Contributor II

@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>"