Script 的內容如下:
#!/bin/bash
echo -n " Give me the name of the file containing user data..."
read file
[ ! -f $file ] && ( echo " '$file' does not exist..."; exit 1 )
while read username password
do useradd $username >/dev/null 2>&1
if [ $? -ne 0 ]
then echo " Fail to create an account with name=$username..."
else echo $password | passwd --stdin $username >/dev/null 2>&1
[ $? -ne 0 ] && echo " Fail to set password for '$username'..."
fi
done < $file
下載 script