星期五, 十一月 30, 2007

通过bash脚本批量创建用户并设置密码

Create Users And Change Passwords With A Bash Script
通过脚本批量创建用户并设置密码

First create a file which contains all the user name.
首先创建一个包还所有用户名的文件,格式如下:
------------------------
nurealam
nayeem
mrahman
farid
rubi
sankar
------------------------
Save the file as userlist.txt. Now create the following bash file:
把该文件保存为userlist.txt。现在创建如下的bash文件:
------------------------
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
adduser $i
done
---------------------------
保存文件为useradd.sh。
运行该脚本文件:
--------------------
[lax@liulantao-com ~]# sh useradd.sh
---------------------
This will add all the users to the system. Now we have to change the
passwords. Let's say we want username123 as password. So for user
nayeem the password will be nayeem123, rubi123 for user rubi and so
on.----www.liulantao.com-----
结果是添加了所有用户名到系统中。现在必须修改密码了。假设我们用使用username123为密码。比如rubi的密码将是rubi123,依此类推。
Create another bash file as follows:
创建下面的脚本文件:
-------------------
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i"123" | passwd –-stdin "$i"
echo; echo "User $username's password changed!"
done
--------------------
保存为userpasswd.sh。
-------------
[lax@liulantao-com ~]# sh userpasswd.sh
------------
Run the file. All the passwords are changed.
运行该文件。所有的密码被修改


--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------
转载本网站文章请保留这一行和以上所有文字,谢谢。

0 条评论:

发表评论

懒桃儿祝大家生活愉快!欢迎大家在此处发表评论:

订阅 博文评论 [Atom]

<< 主页