Scripting question - maintaining accurate User Record in JSS

ocla__09
Contributor

I have been looking for the best way to maintain accurate User and Location records for computers in the JSS and have a script written to help achieve this. This is all in the attempt to have accurate information for user level SCEP requests.

#!/bin/sh
User=$(stat -f %Su "/dev/console")

if [ $User == "root" ]; then
/usr/local/bin/jamf recon
else
/usr/local/bin/jamf recon -endUsername $User
fi

Essentially what I want to add to the "if [ $User == "root" ]; then" section is another account (say "admin") and any accounts that begin with !. Would that be something to the effect of...

if [ $User == "root","admin","!*" ]; then .......?

Essentially if the user is root, admin, or begins with !, just do a regular recon, if any other account, update the user record in the JSS with the current user. Looking for some help on that syntax.

Of course if anybody has an entirely different and better way I am all ears :). I get a handful of errors like below every day with this script:
There was an error.

Connection failure: "A server with the specified hostname could not be found."

Error running script: return code was 1. The results of this policy were not logged at the time of execution.

Thanks!

2 REPLIES 2

raymondap
New Contributor III

The ! makes things a little tricker, but I think you're looking for this syntax:

if [ $User == 'root' ] || [ $User == 'admin' ] || [[ $User = !* ]]
then

We do something similar, but a little more complicated since we have to take shared computers into account.

ocla__09
Contributor

Thank You Much!