Importing users from Windows AD
I hope I understand your question. This might get you going in the right direction.
#!/bin/ksh -x
# This script will login to the Windows Active Directory and grab a list of
# all the windows users and filter out the users that you don't want to
# create a linux account for. Then it will create a linux account and
# home directory.
# SMBUSER must be a name in the Domain Admin group. SMBPASS is the Domain Admin user's password.
# WORKGROUP is the NETBIOS DOMAIN name.
# SMBSERVER is one of the Domain Controller that has AD names.
# TMP_LIST is the list of all Windows users.
# TMP_USERS is the list of Windows users that you want to create Linux accounts for.
#EXCLUDE is a list of users that are in TMP_LIST that you don't want to create a linux account for.
SMBUSER=administrator
SMBPASS=password
WORKGROUP=DOMAINNAME
SMBSERVER=IPADDRESS
TMP_LIST="/tmp/list.tmp"
TMP_USERS="/tmp/users.tmp"
EXCLUDE="/tmp/non_user_list.txt"
# This command is used to get all the users in Windows Active Directory
net rpc user -l -U ${SMBUSER}%${SMBPASS} -W $WORKGROUP -S $SMBSERVER > $TMP_LIST
# This line is used to eliminate unwanted accounts from windows.
cat $TMP_LIST | awk '{print $1}' | grep -v -f $EXCLUDE | grep -v '^$' > $TMP_USERS
# make a backup of the password and shadow file.
cp -p /etc/passwd /etc/passwd.bak
cp -p /etc/shadow /etc/shadow.bak
# foreach user in MSWindows lookup it in the Unix database.
for user in `cat $TMP_USERS`; do
# Check if the user already exists in unix database
grep -q ^${user}: /etc/passwd
if [ "$?" != "0" ]; then
# If the users don't exist then this line will create an account
# and home directory for them.
/usr/sbin/useradd -c "$user" -d /home/$user -m -g 100 -s /bin/ksh $user
|