可以通过在多个send之间添加sleep语句来隔离多条命令的执行,例如:

#!/usr/bin/expect

set timeout 30
spawn ssh user@host

expect "password:"
send "password\n"

expect "$ "
send "command1\n"
sleep 1

expect "$ "
send "command2\n"
sleep 1

expect "$ "
send "command3\n"

expect "$ "
send "exit\n"

在上面的示例中,每个send命令执行后都会等待1秒钟,以便确保前一个命令已经执行完成后再执行下一个命令。这样可以避免多个命令同时执行而导致的混乱。

ubuntu执行expect脚本执行多条命令send怎么隔离

原文地址: https://www.cveoy.top/t/topic/hwQc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录