gpt4 book ai didi

expect - log_file 命令不在 Expect 脚本中记录命令的输出

转载 作者:行者123 更新时间:2023-12-05 07:49:16 28 4
gpt4 key购买 nike

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

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 时,里面什么也没有。有人能告诉我到底哪里错了吗。我使用的 expect 版本是 5.26.0

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

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

输出 生成 telnet 10.1.1.2 parent:WAITING同步字节 parent :告诉 child 继续前进 parent:现在与 child 不同步 spawn:返回 {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>`

最佳答案

您的提示包含导致模式匹配失败的颜色代码:

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

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

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

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

expect -re {> $} 

关于expect - log_file 命令不在 Expect 脚本中记录命令的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37540520/

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