加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 如何将变量从shell脚本传递到expect脚本?

发布时间:2020-12-15 17:02:20 所属栏目:安全 来源:网络整理
导读:我的 shell脚本如下: #!/bin/bashecho "Select the Gateway Server:"echo " 1. Gateway 1"echo " 2. Gateway 2"echo " 3. Gateway 3"read gatewayHostcase $gatewayHost in 1) gateway="abc.com" ;; 2) gateway="pqr.com" ;; 3) gateway="xyz.com" ;; *) ec
我的 shell脚本如下:
#!/bin/bash

echo "Select the Gateway Server:"
echo "   1. Gateway 1"
echo "   2. Gateway 2"
echo "   3. Gateway 3"

read gatewayHost

case $gatewayHost in
    1) gateway="abc.com" ;;
    2) gateway="pqr.com" ;;
    3) gateway="xyz.com" ;;
    *) echo "Invalid choice" ;;
esac

/mypath/abc

在上面的脚本中,我从用户输入选择中获取网关&试图传递给我的abc.sh脚本,这个脚本在下面是:

#!/usr/bin/expect

set timeout 3
spawn ssh "james@$gateway"
expect "password:"
send "TSfdsHhtfsr";
interact

但是我无法将shell脚本中的网关变量传递给期望脚本.谁能告诉我如何实现这一目标?请注意,由于遗留原因,我只需要使用shell脚本(不能使用tcl脚本或者不能在期望脚本本身中执行所有操作)

从你的shell脚本:
/mypath/abc $gateway

从您的期望脚本:

#!/usr/bin/expect

set gateway [lindex $argv 0]; # Grab the first command line parameter

set timeout 3
spawn ssh "james@$gateway"
expect "password:"
send "TSfdsHhtfsr";
interact

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读