Try this....
The file /home/names.txt has the user names (lower case) , groups and the Linux/Samba password.
The Linux and Samba passwords are the same and the user should change them soon after login.
The groups can already exist.
For example.....
fred service 12qwaszx
sam hr 34erdfcv
joe maint 56tyghbn
sally sales 78uijkm
Code:
#!/bin/bash
#
# Ensure that root is running the script.
##
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
echo "You must be root to add news users!"
exit 1
fi
#
clear
NEW_USERS="/home/names.txt"
cat ${NEW_USERS} | \
while read USER GROUP SMBPASS ; do
groupadd ${GROUP} 2> /dev/null
adduser ${USER} -g ${GROUP}
(echo $SMBPASS; echo $SMBPASS) | passwd --stdin ${USER} > /dev/null
echo Added user ${USER}
smbpasswd -e ${USER} -w ${SMBPASS} > /dev/null
(echo $SMBPASS; echo $SMBPASS) | smbpasswd -as ${USER}
echo -e "${USER} = ${USER}" >> /etc/samba/smbusers
done