我有一个用例,在通过ssh连接到主机后需要执行命令。执行命令后,我需要执行Ctrl-D和Ctrl-M,以便可以发出其他命令。
我尝试使用EOF,但是它完全关闭了会话。
expect << EOF
spawn ssh -o StrictHostKeyChecking=no LocalCOMUser@$nodeIp -p $ssh_port
expect {
"password:" {}
timeout { send_user "Timed out in ssh connection" ;exit 1}
}
send "p@ssword\r"
expect {
">" {}
timeout { send_user "Timed out in ssh connection" ;exit 1}
}
set timeout 120
send "mml\r"
expect {
"<" {}
timeout { send_user "Timed out in ssh connection" ;exit 1}
}
send "$command1\r"
expect {
"<" {}
}
send "exit;\r"
expect {
">" {}
timeout { send_user "Timed out in ssh connection" ;exit 1}
}
send "exit\r"
EOF
需要一个按Ctrl-d键起作用的命令。
答案 0 :(得分:1)
您可以通过发送^ D / ␄字符来模拟按下Ctrl-D:
send "\x04"