如何在bash中的ssh expect脚本中自动执行ctrl + d动作?

问题描述 投票:0回答:1

我有一个用例,我需要在通过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方式执行操作的命令。

linux bash ssh expect
1个回答
1
投票

您可以通过发送^ D /␄字符来模拟按Ctrl-D:

send "\x04"
© www.soinside.com 2019 - 2024. All rights reserved.