Wednesday, September 24, 2008

linux adduser bash batch script

#!/bin/bash

NEW_USERS="/path/to/file.txt" #space separated user password group
HOME_BASE="/home/"

cat ${NEW_USERS} | \
while read USER password GROUP
do
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -g ${GROUP} -p ${pass} -m -d ${HOME_BASE}${USER} ${USER}
done

No comments: