批量創建用戶腳本

#!/bin/bash

#create for create many users on 20160816 by babyplus

. /etc/init.d/functions

[ $UID -eq '0' ]||{

  echo "use root run!"

  exit 1

}

mkdir /test -p && touch /test/newuserpassword.txt

for n in `seq -w 2`

do

  pass="`echo $RANDOM|md5sum |cut -c 3-8,10`"

  [ `grep test${n} /etc/passwd|wc -l` -ge '1' ]&&echo "user test${n} is existed!" ||{

  useradd test${n} -M &>/dev/null &&\

  echo $pass |passwd --stdin test${n} &>/dev/null  &&\

   [ $? -eq 0 ]&&{

      action "ok!" /bin/true

      echo test${n}: $pass >>/test/newuserpassword.txt

   }||{

      action "false!" /bin/false

   }

  }

done

exit 0


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章