1.编写脚本
[root@m01 /shell4]# vim user.sh
#!/bin/env bash
#循环在指定的服务器创建用户和文件
while read ip pass
do
/usr/bin/expect <<-END &>/dev/null
spawn ssh root@$ip
expect {
"yes/no" { send "yes
";exp_continue }
"password:" { send "$pass
" }
}
expect "#" { send "useradd yy1;rm -rf /tmp/*;exit
" }
expect eof
END
echo "$ip服务器创建完毕"
done < ip.txt
[root@m01 /shell4]# vim ip.txt
172.16.1.7 123456
172.16.1.8 123456