Shell 如何在expect脚本';s发送

Shell 如何在expect脚本';s发送,shell,expect,Shell,Expect,我编写了一个expect脚本来执行登录操作。登录需要2fa代码,此代码可以通过执行shell命令2fa my_login获得。现在,我如何执行2fa命令并将其输出传递给脚本的send 我需要执行类似于发送--“$(2fa my_login)”的操作。$(2fa my_login)的输出应该传递给send 我的剧本 #!/usr/bin/expect -f set timeout -1 spawn /home/local/apps/forticlientsslvpn/64bit/forticl

我编写了一个expect脚本来执行登录操作。登录需要2fa代码,此代码可以通过执行shell命令
2fa my_login
获得。现在,我如何执行2fa命令并将其输出传递给脚本的send

我需要执行类似于
发送--“$(2fa my_login)”
的操作。$(2fa my_login)的输出应该传递给send

我的剧本

#!/usr/bin/expect -f

set timeout -1

spawn /home/local/apps/forticlientsslvpn/64bit/forticlientsslvpn_cli --server vpn.vpn-domain.com:10443 --vpnuser user-id

expect "Password for VPN:"

send -- "pass\n"

expect "Enter the time-based OTP generated in your device."

send -- "$(2fa my_login)\n"

expect eof
使用


请尝试
send$(2fa my\u login)
send“$(2fa my\u login)”
不,它不起作用。第一个抛出errow,第二个抛出变量notfoundexpect,它使用与shell不同的语法。您必须学习Tcl才能使用Expect。如果您对shell语法更熟悉,可以尝试我的。如果您必须使用Tcl,请参阅以了解如何运行命令和获取输出。感谢@sexpect--Expect\u for \u shell我切换到sexpect,这是一件轻而易举的事。
#!/bin/bash

export SEXPECT_SOCKFILE=/tmp/sexpect-bc-iGciUZ.sock

sexpect spawn -close-on-exit /home/local/apps/forticlientsslvpn/64bit/forticlientsslvpn_cli --server vpn.vpn-domaincom:10443 --vpnuser user

sexpect expect  -glob "Password for VPN:"

sexpect send -enter -- "pass"

sexpect expect  -glob "Enter the time-based OTP generated in your device."

auth=$(2fa my_login)

sexpect send -enter -- $auth

sexpect wait