中国网管论坛's Archiver

haoyan800 发表于 2008-1-13 14:36

如何快速建立多个帐号

首先把要建立的帐号以及密码写在一个资料文件内,每一行有两个字段:

  o 第一个字段为 username,

  o 第二个字段为 password,两个字段间以一或多个空白隔开。

  例如:

  john iLoveMary

  mary iHateJohn

  jason mmmmmm

  maggie iAmLonely

  ? 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

  [url=http://http://main.rtfiber.com.tw/~changyj/linuxtips/html/s.20020314a][color=#0000ff] 下载 script[/color][/url]

  ?其它说明:

  o 执行时会要求你输入资料文件名。

  o 若帐号已经存在,程序将显示错误讯息并且略过该帐号

ssp0203 发表于 2008-6-14 01:24

dddddddddddddd

页: [1]

Powered by Discuz! Archiver 6.1.0  © 1999-2008 bbs.bitsCN.com