我需要使用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
我还想知道如何使用条件语句执行expect脚本 仅当某个命令的输出为负或时,才执行命令列表。这与执行grep类似,而不是使用if,else或while语句进一步执行脚本。
由于 阿维纳什