gpt4 book ai didi

linux - 在 Linux 上使用 Expect 模块将屏幕输出捕获到文件

转载 作者:太空宇宙 更新时间:2023-11-04 04:04:26 24 4
gpt4 key购买 nike

我需要从使用 Expect 脚本执行的许多命令中捕获特定命令的屏幕输出。该脚本在不捕获该命令的输出的情况下运行得很好,但是它没有达到目的。

#! /usr/bin/expect -f
set systemTime [clock seconds]
set now [clock format $systemTime -format "%m_%d_%y"]
exec touch ASR$now.txt
set Password "prizer"
set password "banger"
set bye "exit"
set quitconsole "q"
set exitcons "logout"
spawn ssh admin@192.168.95.96
expect "password:"
send "$password\r"
sleep 5
expect "admin>"
send "32\r"
sleep 5
send "\r"
expect "ASR1001>"
send "enable\r"
expect "Password:"
send "$Password\r"
expect "ASR1001#"
send "terminal length 0\r"
expect "ASR1001#"
send "show run \r"
set output [open "ASR$now.txt" "w"] **<<<<<<<<<<<<<<< Fails here**
send "$bye\r"
sleep 5
send "ctrl-]"
sleep 5
send "$quitconsole\r"
expect "admin>"
send "$exitcons\r"
expect eof

我还想知道如何使用条件语句执行期望脚本,如下所示仅当某个命令的输出为负或 时才执行命令列表。这类似于执行 grep 并使用 if、else 或 while 语句进一步执行脚本。

谢谢阿维纳什

最佳答案

我们可以使用 script 命令捕获 Unix/Linux 终端的屏幕输出
命令的用法解释清楚here

关于linux - 在 Linux 上使用 Expect 模块将屏幕输出捕获到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21800950/

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