期望脚本不起作用,终端立即关闭

问题描述 投票:1回答:1

我不知道脚本出了什么问题。我在Iterm终端上设置了一个新的配置文件来运行脚本,但是它永远无法工作并立即关闭。这是脚本:

#!/usr/bin/expect -f

set timeout 120
set secret mysecret
set username asdf
set host {123.456.789.010}
set password password123
log_user 0

spawn oathtool --totp --base32 $secret
expect -re \\d+
sleep 400
set otp $expect_out(0,string)

spawn ssh -2 $username@$host
expect "*assword:*"
send "$password\n"
expect "Enter Google Authenticator code:"
send "$otp\n"
interact
authentication ssh terminal expect
1个回答
0
投票

首先,使用以下命令测试ssh连接:

ssh -v <auser>@<apassword>

这将验证SSH会话的工作。确保不使用ssh -T ...,因为可能需要使用端子才能使expect commands工作。

第二,在脚本的开头至少添加一个expect,以查看是否被调用:

echo

第三,在这种情况下,使用expect "Script running\r" 的bash脚本是否会更好用

© www.soinside.com 2019 - 2024. All rights reserved.