Username script for the JSS to update

EliasG
Contributor

Looking for a new script that I can run on log in to update username status in Casper.

Thanks

2 ACCEPTED SOLUTIONS

karthikeyan_mac
Valued Contributor

We use the below script to update the username. This script runs weekly once between 10AM - 12PM and 2PM-4PM. This will not run recon or update the username if the machine is in login screen.

#!/bin/sh

# Script to report the Username if users logged in
# Created by Karthikeyan Marappan on 10/21/2015

loggedInUser=$( ls -la /dev/console | cut -d " " -f 4 )
if [[ $loggedInUser != root ]];
then
/usr/sbin/jamf recon -endUsername $loggedInUser
else
echo "Login Screen, No user logged in"
fi
exit 0

Thanks & Regards,
Karthikeyan

View solution in original post

unknown_err
New Contributor III

Here's the one we use that's tied to a policy that runs at login. It only updates the username if the user logging in is not root or one of the local admins.

#!/bin/sh
# Script to set the username in the Location information of a computer detail record on the JSS.
# This script will only update the username if the logged in user is not root or any user with admin in the name.
# 7/2/13 - Jehan B Aziz

thisUser=`stat -f '%u %Su' /dev/console | awk '{ print $2 }'`

if [ $thisUser = "root" ]; then
    exit
elif [[ $thisUser == *admin* ]]; then
    exit
else
    jamf recon -endUsername $thisUser
fi

exit 0

View solution in original post

5 REPLIES 5

karthikeyan_mac
Valued Contributor

We use the below script to update the username. This script runs weekly once between 10AM - 12PM and 2PM-4PM. This will not run recon or update the username if the machine is in login screen.

#!/bin/sh

# Script to report the Username if users logged in
# Created by Karthikeyan Marappan on 10/21/2015

loggedInUser=$( ls -la /dev/console | cut -d " " -f 4 )
if [[ $loggedInUser != root ]];
then
/usr/sbin/jamf recon -endUsername $loggedInUser
else
echo "Login Screen, No user logged in"
fi
exit 0

Thanks & Regards,
Karthikeyan

bpavlov
Honored Contributor

There might be a simpler method by creating a script that uses the $3 variable in a policy. When is the script supposed to run? What exactly are you trying to accomplish? You may get a lot of different answers depending on what you want to do none of which may help you with your end goal.

EliasG
Contributor

Pretty much I want to update the names in Casper, and Casper remote to the correct computer.

unknown_err
New Contributor III

Here's the one we use that's tied to a policy that runs at login. It only updates the username if the user logging in is not root or one of the local admins.

#!/bin/sh
# Script to set the username in the Location information of a computer detail record on the JSS.
# This script will only update the username if the logged in user is not root or any user with admin in the name.
# 7/2/13 - Jehan B Aziz

thisUser=`stat -f '%u %Su' /dev/console | awk '{ print $2 }'`

if [ $thisUser = "root" ]; then
    exit
elif [[ $thisUser == *admin* ]]; then
    exit
else
    jamf recon -endUsername $thisUser
fi

exit 0

Aziz
Valued Contributor

I use this for any account that logs in. Set as an ongoing login policy.

if [ -z $3 ]; then currentUser=stat -f '%Su' /dev/console; else currentUser=$3; fi; jamf recon -endUsername $currentUser