[shell脚本]-在shell中定义expect function

概述

  1. 使用shell脚本加expect 实现批量登录,互信等,免交互式操作,之前主要写两个脚本,一个是expect脚本里面主要是接受参数,进行ssh 免交互操作,另一个是shell脚本,里面调用expect的脚本,传入参数,
  2. 现在需要把expect和shell脚本内容全部合并在shell脚本中 可以用shell function 里面定义expect

例子:

  1. shell 脚本中定义function, 然后把<< EOF 所有内容,当作expect 标准输入
#!/bin/bash
function expect_bash(){
/usr/bin/expect << EOF
spawn ssh -o StrictHostKeyChecking=no root@${i} "hostname"
expect {
        "*password:" {exp_send "YNETserver1\r"}
}
expect eof
EOF
}

for i in `cat ip`
do
    expect_bash
done

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...