Wrote this script so that our Helpdesk staff can use Casper Remote to find user's computers via their username.
As a lot of our computers are open to anyone to use, Assigning a Computer to a User hasn't helped us out too much, this reuses that Username Field, while avoiding changes to Room, Building, departments, and such.
Might Be useful for others, I apologize if this has already been addressed, I was unable to find anything like this.
#!/bin/sh
# The purpose of the script is to add the user to the Computer's Location, User attribute.
# This way the helpdesk can lookup where our users are sitting based on their username.
# There is no logoff policy as we might find it useful being static until next login.
# Define the variables
jssAPIUsername="locked down api user"
jssAPIPassword="passwordhere"
# Enter in the hostname in the quotes here, replacing https://jss.organization.com:8443 without the trailing slash
jssAddress="https://jss.organization.com:8443"
# Get Computer Main Mac Address, for lookup via Casper. (Might Fail on Airs)
hwAddress=`/sbin/ifconfig en0 | awk '/ether/ { gsub(":", "."); print $2 }'`
# Get the username used for login.
loggedInUser="$3"
# Do not edit below this line
# -----------------------------------------------------
############################################################
#Start Of Posting Username
#This Grabs the username at login and uses the API to update
#the Username on the computer within casper.
############################################################
## Now that we have the name, we'll basically grab it, put it in a custom xml that will get put into the device's location info
echo "<?xml version="1.0" encoding="utf-8" standalone="no"?>
<computer>
<location>
<username>$loggedInUser</username>
</location>
</computer>" > /tmp/deviceFinal.xml
# Then, take that /tmp/deviceFinal.xml and put it in the JSS for the device
function LogUser {
res=`curl -k -s -I -u $jssAPIUsername:$jssAPIPassword $jssAddress/JSSResource/computers/macaddress/$hwAddress -X PUT -T /tmp/deviceFinal.xml | grep HTTP/1.1 | awk {'print $2'}`
echo "All HTTP Status:
$res"
res=`echo $res | awk {'print $NF'}`
#echo $res
if [ $res -ne "201" ]
then
echo "Error $res"
fi
}
# Call function to Log user into Casper.
LogUser
# Test or display Results
echo "------------------"
echo "Username: $loggedInUser"
echo "Mac Address: $hwAddress"
echo "XML File: "
cat /tmp/deviceFinal.xml
echo "------------------"
# clean up
rm /tmp/deviceFinal.xml
Just create a Policy that runs this at login and your user is updated for each login.
