· 首先把要建立的帳號(hào)以及密碼寫(xiě)在一個(gè)資料文件內(nèi),每一行有兩個(gè)字段: o 第一個(gè)字段為 username, o 第二個(gè)字段為 passWord,兩個(gè)字段間以一或多個(gè)空白隔開(kāi)。 例如: john iLoveMary mary iHateJohn jason mmmmmm maggie iAmLonely · Script 的內(nèi)容如下: #!/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
·其它說(shuō)明: o 執(zhí)行時(shí)會(huì)要求你輸入資料文件名。 o 若帳號(hào)已經(jīng)存在,程序?qū)@示錯(cuò)誤訊息并且略過(guò)該帳號(hào)。