Linux多台机子上创建相同的用户

At 2011-10-11

转载请注明文章转载自:Dbabc.Net [http://dbabc.net]
本文链接:http://dbabc.net/archives/2011/10/11/linux-more-user.shtml

要在20+台的Linux主机上创建一个用户,怎么办?google之。
发现如下可以实现:
expuser.exp 文件

[root@dbabc.net ~]# cat expuser.exp
#!/usr/bin/expect -f
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30
spawn ssh root@$ipaddress
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$passwd\r" }
}
expect "]*"
send "useradd dbabc\r"
send "echo 'dbabc.net' | passwd --stdin testabc\r" 

userfast.sh脚本

[root@dbabc.net ~]# cat userfast.sh
#!/bin/bash
for i in `awk '{print $1}' passwd.txt`
do
j=`awk -v I="$i" '{if(I==$1)print $2}' passwd.txt`
expect ./userfast.exp $i $j
done

password.txt文件,将多个 ip 和密码添加进去,中间用空格隔开

[root@dbabc.net ~]# cat passwd.txt
10.4.1.50 password
10.4.1.51 password
10.4.1.52 password
10.4.1.53 password
10.4.1.54 password

然后执行 userfast.sh 脚本

sh userfast.sh

无觅相关文章插件,快速提升流量

Copyright © Dbabc.Net All Rights Reserved. 本站内容仅代表个人观点, 与其他任何组织或公司无关

-The End-
  • 暂无相关日志

发表评论


*

为你保密









Copyright © Dbabc.Net All Rights Reserved. 本站内容仅代表个人观点, 与其他任何组织或公司无关

Powered by Wordpress and Theme by WPYOU