Skip to main content
Solved

dscl command to list local users but exclude system accounts?


donmontalvo
Forum|alt.badge.img+36

We can use this to get local accounts:

$ dscl /Local/Default -list /Users UniqueID | awk '$2 >= 100 { print $1 }'

But it returns some system accounts. How do we exclude these (they begin with underscore)?

Thanks,
Don

Best answer by jstrauss

Try:

dscl /Local/Default -list /Users UniqueID | awk '$2 >= 100 { print $1 }' | grep -v "_"

Hope this helps!

View original
Did this topic help you find an answer to your question?

Forum|alt.badge.img+9
  • Contributor
  • January 14, 2012

Try:

dscl /Local/Default -list /Users UniqueID | awk '$2 >= 100 { print $1 }' | grep -v "_"

Hope this helps!


donmontalvo
Forum|alt.badge.img+36
  • Legendary Contributor
  • January 16, 2012

Thanks! Works great! Karl responded over at MacEnterprise.org with another variation:

dscl /Local/Default -list /Users uid | awk '$2 >= 100 && $0 !~ /^_/ { print $1 }'

Don


Forum|alt.badge.img+12
  • Contributor
  • January 17, 2012

dscl /Local/Default -list /Users UniqueID | awk '$2 >= 100 { print $1 }' | grep -v "^_"


Forum|alt.badge.img+12
  • Contributor
  • January 17, 2012

Sorry, hit go too quickly. There are already responses. I would however go with mine of Don's, as these explicitly say line starts with an underscore


Forum|alt.badge.img+31
  • Honored Contributor
  • January 17, 2012

Do you have any accounts on your systems that are not used by the system and have a UID of lower than 500?


Forum|alt.badge.img+5
  • Contributor
  • November 6, 2015

Does anyone know how to refine this search to show local administrator accounts only?
Or does anyone know the best way to get a report of all machines with local admin accounts on them?
Thanks,
Matt


Forum|alt.badge.img+31
  • Honored Contributor
  • November 6, 2015

You can try this snip of code @mjohnston

dscl . read /Groups/admin GroupMembership

or

You can run an EA and just check to see if the local account is a member of the admin group every time a device checks in for recon. Example:

#!/bin/bash

currentUser=$(ls -l /dev/console | awk '{ print $3 }')
checkAdmin=$(dseditgroup -o checkmember -m ${currentUser} admin | awk '/yes/ { print $1 }')

if [[ ${checkAdmin} == 'yes' ]]
  then echo "<result>admin true</result>"
  else echo "<result>admin false</reult>"
fi

The above EA would allow you to build a report in the JSS.

Cheers,
Tom


Forum|alt.badge.img+5
  • Contributor
  • November 6, 2015

@tlarkin Thanks for this info. It's moved me forward in the process.
I had already built a report using an EA but I didn't have the script right and it was returned ALL user accounts.
I assume I have to wait until all machines have checked in with Casper until it can populate? It's early here so only a few machines on.
Is there a way I can force ALL machines to check in or do I just have to be patient?

Thanks a bunch.
Matt


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • November 6, 2015

It will depend on your JSS settings, but generally, machines should check in as soon as they come online, especially if they haven't been in contact with the JSS for a little while. I would just wait a bit and run some advanced searches using the EA criteria and see what starts showing up. If all looks good, build your Smart Group.

Also, you can look at my post here for a more involved/advanced EA script that will report on all accounts on the Mac and whether they are local or domain as well as admin or standard.
https://jamfnation.jamfsoftware.com/featureRequest.html?id=2065#responseChild10170


Forum|alt.badge.img+5
  • Contributor
  • November 6, 2015

Thanks a bunch for all your help.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings