在提示之前期待垃圾

我尝试使用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:~# 

此问题的主要原因是什么?我该如何解决?

HU9694 回答:在提示之前期待垃圾

问题是发出了终端转义序列,可能是 来控制终端使用什么颜色。最简单的解决方法是在进行void zidi_kopec(int **mapa,int n,int ki,int kj) { int i,j,max; while (ki != 0 && ki != n - 1 && kj != 0 && kj != n - 1) { max = 0; // sever if (ki - 1 >= 0 && mapa[ki - 1][kj] > max && mapa[ki - 1][kj] < mapa[ki][kj]) { i = ki - 1; j = kj; max = mapa[i][j]; } // vychod if (kj + 1 < n && mapa[ki][kj + 1] > max && mapa[ki][kj + 1] < mapa[ki][kj]) { i = ki; j = kj + 1; max = mapa[i][j]; } // juh if (ki + 1 < n && mapa[ki + 1][kj] > max && mapa[ki + 1][kj] < mapa[ki][kj]) { i = ki + 1; j = kj; max = mapa[i][j]; } // zapad if (kj - 1 >= 0 && mapa[ki][kj - 1] > max && mapa[ki][kj - 1] < mapa[ki][kj]) { i = ki; j = kj - 1; max = mapa[i][j]; } printf("i: %d,j: %d,vyska: %d\n",i,max); ki = i; kj = j; } } 之前,将终端类型(环境变量)设置为不支持颜色的内容。也许可以做到这一点:

spawn

如果这不起作用(这完全取决于某人的set env(TERM) "dumb" 中的内容),则可以在登录后使用第一个命令在远程端覆盖.bashrc环境变量内。

PS1
本文链接:https://www.f2er.com/2549357.html

大家都在问