shell脚本和expect结合使用,在多台服务器上创建1个用户
作者:
有事找叮当 | 来源:发表于
2020-03-13 21:07 被阅读0次1. 循环
2. 登录远程主机——>ssh——>从ip.txt文件里获取IP和密码分别赋值给两个变量
3. 使用expect程序来解决交互问题
#!/bin/bash
# 循环在指定的服务器上创建用户和文件
while read ip pass
do
/usr/bin/expect <<-END &>/dev/null
spawn ssh root@$ip
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$pass\r" }
}
expect "#" { send "useradd yy1;rm -rf /tmp/*;exit\r" }
expect eof
END
done < ip.txt
本文标题:shell脚本和expect结合使用,在多台服务器上创建1个用户
本文链接:https://www.haomeiwen.com/subject/fjmyshtx.html
网友评论