lundi 5 janvier 2015

How to make a filter more efficient


I've created a script to compare a list of users from a MSSQL database against a list of disabled AD users. The tool we use for AD authentication returns data in the following format (with plenty more whitespace in between the columns), so to allow the compare (in python) the data needs to be parsed:



User info (Level-2):
====================
Name: domain\username
UPN: UserName@domain.local
Generated UPN: NO
DN: DN....
Uid: 123456
Gid: 123456
Gecos: User Name
Shell: /shell/path
Home dir: /homedir
Other attributes: ....
Other attributes: ....
Account disabled (or locked): TRUE
Other attributes: ....
Other attributes: ....
Other attributes: ....
etc


From the command line, the following does the trick, however it's very messy and I'm hoping someone may be able to suggest a cleaner method. I've experimented with awk but haven't had much success in reducing the size of the command:



/opt/util/enum-users --level 2 | grep "Name:\|Account disabled (or locked): TRUE" | grep -x "Account disabled (or locked): TRUE" -B 1 | grep "Name:" | sed -r 's/^.{35}//'


This outputs the data as required:



username
username
etc


Aucun commentaire:

Enregistrer un commentaire