How to list active samba users?

1

I could not find a pdbedit or smbldap-userlist option to list just the active samba users.

Solution on Question [1] lists all users and machines and smbldap-userlist -ua lists all users, even if they are inactive. I mean Inactive, not a logged off user but a user that is not active on the domain anymore.

I tried awk and grep to parse the output but I could not match a pattern on [status SMB] column.

Does somebody has a command-line or shell solution? (although, a Python solution will be very welcome)

[1] List Samba users?

Josir

Posted 2011-09-23T20:10:54.697

Reputation: 11

What do you mean with a user that is not active on the domain? Do you mean that you would like to hide accounts that are disabled? – jelmer – 2017-05-06T03:31:08.940

Answers

3

The "smbstatus" tool should show the currently active users on a server. There might be some false positives as workstations often keep connections open after a user has logged off.

jelmer

Posted 2011-09-23T20:10:54.697

Reputation: 315

Thanks for the reply. But I didn't explain the problem well. I want the users that CAN login, not the users logged on a certain time. I rephrased the question. – Josir – 2011-11-09T19:16:17.060

0

you may use the following simple bash script. It rules out machine accounts and disabled accounts (account flags W and D)

#!/bin/bash    
cd ~
lista=`pdbedit -L | sort | uniq | cut -f1 --delimiter=':'`

for i in $lista
do
        ret=`pdbedit -L -v $i | grep "Account Flags" | cut -f2 --delimiter='[' | cut -f1 --delimiter=' '`
        ismachine_account=`echo $ret | grep W | wc -l`
        isdeleted_account=`echo $ret | grep D | wc -l`
        if [ $ismachine_account -eq 0 -a $isdeleted_account -eq 0 ]; then
                echo $i
        fi
done    
exit

Savvas Pavlidis

Posted 2011-09-23T20:10:54.697

Reputation: 1