zoukankan      html  css  js  c++  java
  • 脚本连接主机创建用户expect

    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

  • 相关阅读:
    2020/3/12
    练习题1
    2020/3/26
    2020/3/25
    2020/3/24
    2020/3/23
    应用层
    bzoj3326[SCOI2013]数数
    HEOI2017游记
    bzoj4417[SHOI2013]超级跳马
  • 原文地址:https://www.cnblogs.com/chenlifan/p/13837162.html
Copyright © 2011-2022 走看看