小编Cod*_*upt的帖子

在 bash 脚本中保持 SSH 开放

在任何人说使用公钥之前,这不是一个选项,因为我正在与客户服务器打交道。

我有一个脚本来维护一个文件,其中包含我客户服务器的所有 IP/用户名/密码。通过脚本,我选择了一个服务器并使用 here 文档来登录该服务器。

#### Code up here to set the variables.
exp_internal 1
/usr/bin/expect << EOFFF

if { $USE_TUNNEL == 1 } {
        spawn ssh -L 4567:localhost:3306 $user\@$ip
} else {
        spawn ssh $user\@$ip
}
expect {
    -re ".*es.*o.*" {
        exp_send "yes\r"
        exp_continue
    }
    -re ".*sword.*" {
        exp_send "$pass\r"
    }
}
expect {
    "$ " { send "<<<Send stuff>>>" }
    "# " { send "<<<Send stuff>>>" }
}
interact
EOFFF
# End of bash script
Run Code Online (Sandbox Code Playgroud)

我的问题是,在 here 文档结束后,它会关闭 …

ssh bash heredoc expect spawn

2
推荐指数
1
解决办法
1273
查看次数

标签 统计

bash ×1

expect ×1

heredoc ×1

spawn ×1

ssh ×1