我有这个代码ssh到设备并使用expect,i log_file命令的所有输出。该命令非常快速地返回大约2000行输出。 1/2次,输出被击中并且永远不会结束,除非我杀死了unix中的ssh进程
proc SSHSendCommand {args} {
array set aArgs $args
# supported options
# -spawn_id (required)
# -cmd (required)
# -timeout (optional. Default=60s)
# -buffer_size (optional. Default=2000)
# -log (optional.)
if {$aArgs(-spawn_id) == 0} {
puts ": got spawn_id of \"0\". Not logged in."
return ""
}
# set default value for timeout
if {![info exists aArgs(-timeout)]} {
set aArgs(-timeout) 60
}
if {[info exists aArgs(-log)]} {
log_file -noappend $aArgs(-log)
}
# flush the expect buffer
if {[catch {expect {
-timeout 1
-i $aArgs(-spawn_id)
-re {.*} {} }
} sError ]} {
# caught error, connection may have been lost and shut down
puts "WARNING: Caught error in : $sError"
return ""
}
if {[catch {
# send the command
exp_send -i $aArgs(-spawn_id) "$aArgs(-cmd)\r"
set sResponse ""
# wait for the command prompt to return
expect {
-timeout $aArgs(-timeout)
-i $aArgs(-spawn_id)
-re {#} {}
timeout {puts "Timed out waiting for command prompt to return";
return ""
}
}
} sError]} {
# caught error
puts "WARNING: caught error during : $sError"
set sResponse ""
}
log_file
# return the response text
return $sResponse
}
命令输出的时间在5秒内完成..,超时给出60秒