gpt4 book ai didi

linux - 两个命令或命令管道命令 - Spawn Expect

转载 作者:太空宇宙 更新时间:2023-11-04 12:36:10 34 4
gpt4 key购买 nike

我正在尝试将 expect 脚本执行到 bash 脚本中,但是当我尝试在没有 "| tee -a xxx.log"的情况下执行 shell 时(其中 xxx.log 是一个文件,而不是我想写信来记录 ssh session )。

这段代码工作正常:

comlog="ssh $USR@192.168.228.20"
expect -c"
spawn \"$comlog\"
expect \"Password:\"
send \"$PASS\r\"
interact
"

但是当我尝试添加“tee -a”命令来保存 ssh session 时,问题是

invalid command name "ssh"
while executing

这是我获得错误信息的完整命令

 comlog="ssh $USR@192.168.228.20 | tee -a /home/xxx.log"
expect -c"
spawn \"$comlog\"
expect \"Password:\"
send \"$PASS\r\" #Already Obteined
interact
"

我尝试用这种方式更改“comlog”var 但不起作用:(

 cssh $USR@192.168.228.20 \| tee -a /home/xxx.log

有谁知道另一种方法来保存从 expect 开始的 ssh session ?或者我如何在同一个 spawn 命令中发送这两个命令。

最佳答案

您可以通过这种方式捕获期望的 session 输出:

 comlog="ssh $USR@192.168.228.20"
expect -c"
spawn \"$comlog\"
expect \"Password:\"
send \"$PASS\r\" #Already Obteined
interact
" >/home/xxx.log

关于linux - 两个命令或命令管道命令 - Spawn Expect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41723613/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com