繁体   English   中英

如何在期望脚本的发送中使用 shell 命令的 output

[英]How to use the output of the shell command in expect script's send

我编写了一个期望脚本来执行登录操作。 登录需要 2fa 代码,该代码可以通过执行 shell 命令2fa my_login 现在如何执行2fa命令并将其 output 传递我的脚本发送?

我需要做一些类似send -- "$(2fa my_login)"的事情。 $(2fa my_login) 的 output 应传递给发送。

我的剧本

#!/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

使用期望

#!/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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM