Skip to main content
Question

Searching local user accounts

  • November 15, 2012
  • 4 replies
  • 0 views

Forum|alt.badge.img+2

I am trying to search local user accounts, specifically UID's in the range of 502-505. Is there a way or script I could use to do this?

4 replies

Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • November 15, 2012

What exactly do you mean. Searching via a script run from a policy or Casper Remote? Or do you mean running an inventory report in the JSS?

Anyway, looking up local account UIDs is pretty easy if you meant from a script.
If you really only want the UIDs between 502 and 505, try this-

dscl . list /Users UniqueID | awk '$2 >= 502 && $2 <= 505 {print $1}'

That would include UID 502 and 505. Not sure if you meant greater than and less than or including those. If you meant the former, just remove the 2 = symbols in the above.

If instead you want all local accounts from UID 501 and up, use:

dscl . list /Users UniqueID | awk '$2 > 500 {print $1}'

Forum|alt.badge.img+2
  • Author
  • New Contributor
  • 1 reply
  • November 16, 2012

Trying to find users that dont have a manage account. Local users that have managed accounts have a long UID and those that just have a local account are in the 502-505 range. 501 UID is the local admin that we put on with every image.


Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • November 16, 2012

I see. So then you're using a directory service for your regular user accounts. The long UID numbers you describe are typical of either OD and AD based accounts. I don't recall where OD account UIDs start. I believe AD starts at 1000 and up. You may be better off with a command that will look through everything up to the start of your directory based accounts and excluding 501. But you can do it however you want.


Forum|alt.badge.img+18
  • Valued Contributor
  • 1007 replies
  • November 16, 2012

here is a perl subroutine that checks for local users, and reports true, you could edit the else section and delete the accounts or whatever else if you so desire.

sub checkForLocalUsers { my $rc = 'false'; my $user_dir = '/private/var/db/dslocal/nodes/Default/users'; my $dscl_cmd = 'dscl . -read Users/'; my @userlist; opendir E, $user_dir or die "Users Directory $! "; @userlist = readdir(E); closedir E; foreach my $u (@userlist) { next if $u =~ /^_/; next if $u =~ /^./; (my $uname = $u) =~ s/.plist$//; my $newcmd = $dscl_cmd . $uname . " UniqueID"; my $uid = (split /:/, `$newcmd`)[1]; if ($uid < 501) { next; } else { $rc = 'true'; last; } } return $rc;
}


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