Tcl 在提示之前需要垃圾

Tcl 在提示之前需要垃圾,tcl,expect,garbage,Tcl,Expect,Garbage,我尝试使用ssh连接到路由器,以便从中自动提取一些日志 我开发了以下代码: #!/usr/bin/expect -f spawn ssh root@192.168.1.1 expect "Are you sure you want to" send -- "yes\r" expect "password" send -- "root\r" expect "\#" send -- "ls\r" expect "\#" 问题是我希望在输出日志中的提示符之前出现一个垃圾 spawn ssh roo

我尝试使用ssh连接到路由器,以便从中自动提取一些日志

我开发了以下代码:

#!/usr/bin/expect -f

spawn ssh root@192.168.1.1
expect "Are you sure you want to"
send -- "yes\r"
expect "password"
send -- "root\r"
expect "\#"
send -- "ls\r"
expect "\#"
问题是我希望在输出日志中的提示符之前出现一个垃圾

spawn ssh root@192.168.1.1
The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
RSA key fingerprint is SHA256:6aeE74qXMeQzg0SGJBZMIa0HFQ5HJrNqE5f3XZ6Irds.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/amin/.ssh/known_hosts).

root@192.168.1.1's password: 


BusyBox v1.30.1 () built-in shell (ash)


OpenWrt Version: ALPHA
OpenWrt base: 19.07
------------------------------------
]0;root@openwrt: ~root@openwrt:~# ls
[0;0mnetwork[m
]0;root@openwrt: ~root@openwrt:~# 

这个问题的主要原因是什么?我如何修复它?

问题是正在发布终端转义序列,可能是为了控制终端使用的颜色。最简单的修复方法是在执行
spawn
之前,将终端类型(环境变量)设置为不支持颜色的类型。也许这会奏效:

set env(术语)“dumb”
如果这不起作用(具体取决于某人的
.bashrc
中的内容),那么您可以在登录后使用第一个命令覆盖远程端的
PS1
环境变量


可能是一个逃逸的EOF…顺便说一句,我会使用SSH身份验证而不是存储密码…如果我看得更仔细的话,这些也可能是ANSI颜色代码…@dan1st如何删除它们?关于什么?我添加了这一行:set env(术语)“dumb”,效果很好。谢谢
# etc for logging in
expect "# "
send "PS1='# '\r"
expect "# "
# Everything should be right from here on