log_file命令未在Expect脚本中记录命令的输出 [英] log_file command not logging the output of a command in Expect script

查看:393
本文介绍了log_file命令未在Expect脚本中记录命令的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行调试命令以将命令的输出记录到文件中.我尝试了log_file命令,但它没有记录输出.我的代码如下:

I'm running a debug command to log the output of my command to a file.I tried the log_file command but it doesnt log the output.My code is as follows:

log_file -a gdb.txt 
send "~/debugulator.sh $file mns20\r"
log_user 0
expect -re {DSP.*0x[0-9][0-9][0-9][0-9]}
log_user 1
send_log $expect_out(0,string)
log_file 

但是当我打开gdb.txt时,里面什么都没有.有人可以告诉我我到底要去哪里.我使用的期望版本是5.26.0

But when I open gdb.txt,nothing is inside.Can somebody tell me where exactly am I going wrong.The version of expect I'm using is 5.26.0

更新 这是我正在尝试的另一段代码...它仍然不起作用..我在添加exp_internal 1命令后发布了输出..代码如下:

UPDATE Here is the other piece of code I was trying...It still doesnt work..I have posted the output after adding the exp_internal 1 command..The code is as follows:

spawn telnet 10.1.1.2
expect "Login:"
send "xyz\r"
expect "Password:"
send "Nxyz1\r"
expect "xyz:/home/xyz>"
send "cd /sonus/support/GSX-[lindex $argv 0]\r"
log_file myfile.log
send_log "this is in the log file \n"
log_file
interact

输出 spawn telnet 10.1.1.2 parent: waiting for sync byte parent: telling child to go ahead parent: now unsynchronized from child spawn: returns {17179}

OUTPUT spawn telnet 10.1.1.2 parent: waiting for sync byte parent: telling child to go ahead parent: now unsynchronized from child spawn: returns {17179}

`expect: does "" (spawn_id exp6) match glob pattern "Login:"? no`
`Trying 10.1.1.2...`

`expect: does "Trying 10.1.1.2...\r\n" (spawn_id exp6) match glob pattern "Login:"? no`
`Connected to 10.1.1.2.`
`Escape character is '^]'.`

`expect: does "Trying 10.1.1.2...\r\nConnected to 10.1.1.2.\r\nEscape     character is '^]'.\r\n" (spawn_id exp6) match glob pattern "Login:"? no`


`SunOS 5.9`


`expect: does "Trying 10.1.1.2...\r\nConnected to 10.1.1.2.\r\nEscape character is '^]'.\r\n\r\n\r\nSunOS 5.9\r\n\r\r\n\r" (spawn_id exp6) match glob pattern "Login:"? no
login: xyz\r`
`expect: does "Trying 10.1.1.2...\r\nConnected to 10.1.1.2.\r\nEscape character is '^]'.\r\n\r\n\r\nSunOS 5.9\r\n\r\r\n\rlogin: " (spawn_id exp6) match glob pattern "Login:"? no`
`expect: timed out`
`send: sending "xyz\r" to { exp6 }`

`expect: does "Trying 10.1.1.2...\r\nConnected to 10.1.1.2.\r\nEscape character is '^]'.\r\n\r\n\r\nSunOS 5.9\r\n\r\r\n\rlogin: " (spawn_id exp6) match glob pattern "Password:"? no

xyz`

 `expect: does "Trying 10.1.1.2...\r\nConnected to 10.1.1.2.\r\nEscape character is '^]'.\r\n\r\n\r\nSunOS 5.9\r\n\r\r\n\rlogin: xyz\r\n" (spawn_id exp6) match glob pattern "Password:"? no`
 `Password:` 
 `expect: does "Trying 10.1.1.2...\r\nConnected to 10.1.1.2.\r\nEscape character is '^]'.\r\n\r\n\r\nSunOS 5.9\r\n\r\r\n\rlogin: xyz\r\nPassword: " (spawn_id exp6) match glob pattern "Password:"? yes`
 `expect: set expect_out(0,string) "Password:"`
 `expect: set expect_out(spawn_id) "exp6"`
 `expect: set expect_out(buffer) "Trying 10.1.1.2...\r\nConnected to 10.1.1.2.\r\nEscape character is '^]'.\r\n\r\n\r\nSunOS 5.9\r\n\r\r\n\rlogin: xyz\r\nPassword:"`
 `send: sending "Nxyz1\r" to { exp6 }`

 `expect: does " " (spawn_id exp6) match glob pattern "xyz:/home/xyz>"? no`


 `expect: does " \r\n" (spawn_id exp6) match glob pattern "xyz:/home/xyz>"? no`
 `Last login: Tue May 31 05:10:20 from 10.253.6.98
 /home/xyz/.aliases: No such file or directory.`
 `[1]slate:xyz:/home/xyz>` 
 `expect: does " \r\nLast login: Tue May 31 05:10:20 from 10.253.6.98\r\n/home/xyz/.aliases: No such file or directory.\r\n\u001b]0;[slate:]/home/xyz\u0007[1]slate:\u001b[1mxyz\u001b[m:/home/xyz> " (spawn_id exp6) `match      glob pattern "xyz:/home/xyz>"? no
 `expect: timed out`
 `send: sending "cd /sonus/support/GSX-5\r" to { exp6 }`
 `tty_raw_noecho: was raw = 0  echo = 1`
 `spawn id exp6 sent <c>`
 `cspawn id exp6 sent <d /sonus/support/GSX-5\r\r\n\u001b]0;[slate:]/sonus/support/GSX-5\u0007[2]slate:\u001b[1msdwarampudi\u001b[m:/sonus/support    /GSX-5> >`
 `/sonus/support/GSX-5`
`[2]slate:xyz:/sonus/support/GSX-5>` 

推荐答案

您的提示中的颜色代码导致图案匹配失败:

Your prompt has colour codes that are causing the pattern match to fail:

expect: does "...slate:\u001b[1mxyz\u001b[m:/home/xyz> " (spawn_id exp6) `match      glob pattern "xyz:/home/xyz>"? no
# .................................^^^^^^^^........................................................^^^^^^^^^^^^^^

通常当我SSH到远程主机时,我要做的第一件事是(假设远程Shell是sh/ksh/bash)将提示设置为易于匹配的内容:

Often when I ssh to a remote host, the first thing I'll do is (assuming the remote shell is sh/ksh/bash) set the prompt to something that's easy to match:

spawn ssh remotehost
# ... password stuff
# now, set the prompt
send "PS1='>'\r"
expect -re {>$}    # use this to match the prompt from now on

实际上,您所需要做的就是简化提示符匹配:提示符以>和空格结尾,因此:

Actually, all you need to do is simplify your prompt matching: your prompt ends with a > and a space, so:

expect -re {> $} 

这篇关于log_file命令未在Expect脚本中记录命令的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆