阿豪IT部落

關於部落格
電腦教學、學習、教師網誌
  • 161269

    累積人氣

  • 41

    今日人氣

    0

    訂閱人氣

大量建帳號linux from vbird

#!/bin/bash
#
# History:
# 2005/09/05    VBird   剛剛才寫完,使用看看先~
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH
accountfile="user.passwd"

# 1. 進行帳號相關的輸入先!
read -p "帳號開頭代碼 ( Input title name, ex> std )======> " username_start
read -p "起始號碼 ( Input start number, ex> 520 )========> " nu_start
read -p "帳號數量 ( Input amount of users, ex> 100 )=====> " nu_amount
read -p "是否同步建立samba帳戶 1) 是  2)否 ==============> " sam
read -p "shell登錄設定 1)不允許登錄 2)允許登錄 ===========>" shell_login
read -p "密碼標準 1) 與帳號相同 2)亂數自訂 ==============> " pwm
if [ "$username_start" == "" ]; then
        echo "沒有輸入開頭的代碼,不給你執行哩!" ; exit 1
fi
testing1=`echo $nu_amount | grep '[^0-9]' `
testing2=`echo $nu_start  | grep '[^0-9]' `
if [ "$testing1" != "" ] || [ "$testing2" != "" ]; then
        echo "輸入的號碼不對啦!有非為數字的內容!" ; exit 1
fi
if [ "$pwm" != "1" ]; then
        pwm="2"
fi

# 2. 開始輸出帳號與密碼檔案!
[ -f "$accountfile" ] && mv $accountfile "$accountfile"`date +%Y%m%d`
nu_end=$(($nu_start+$nu_amount-1))
for (( i=$nu_start; i<=$nu_end; i++ ))
do
        account=$username_start$i
        if [ "$pwm" == "1" ]; then
                password="$account"
        else
                password=""
                test_nu=0
                until [ "$test_nu" == "8" ]
                do
                       temp_nu=$(($RANDOM*50/32767+30))
                        until [ "$temp_nu" != "60" ]
                        do
                                temp_nu=$(($RANDOM*50/32767+30))
                        done
                        test_nu=$(($test_nu+1))
                        temp_ch=`printf "x$temp_nu"`
                        password=$password$temp_ch
                done
        fi
        useradd -m "$account" -s "$shell"
        if [ "$sam" == "1" ]; then
        echo -e "$passwordn$password"|smbpasswd -a -s "$account"
        fi
        echo "$account":"$password" | tee -a "$accountfile"
done

# 3. 開始建立帳號與密碼!
        chpasswd < "$accountfile"
        pwconv
        echo "OK!建立完成!"
-----------------------------------------------------------------

鳥哥的script 我再加一點其它的設定。

相簿設定
標籤設定
相簿狀態