Linux 远程提示需要ssh reg_ex
我有一个shell脚本,它使用expect启动到另一台服务器的ssh会话并列出一个目录。它工作正常,但我的问题是,登录后处理远程提示的最佳方式是什么?例如,以下是我目前掌握的情况:Linux 远程提示需要ssh reg_ex,linux,shell,expect,Linux,Shell,Expect,我有一个shell脚本,它使用expect启动到另一台服务器的ssh会话并列出一个目录。它工作正常,但我的问题是,登录后处理远程提示的最佳方式是什么?例如,以下是我目前掌握的情况: # Wait for the prompt on a remote ssh server -re "\[%|>|\$|#\] $" { send "ls -1t /home/user/\r" expect { "*not found" {
# Wait for the prompt on a remote ssh server
-re "\[%|>|\$|#\] $" {
send "ls -1t /home/user/\r"
expect {
"*not found" {
puts "\nDirectory not found\n"
exp_continue
}
timeout { puts "\ntimeout happened\n" }
-re "\[%|>|\$|#\] $" {
puts "Exiting..."
send "exit\r"
return
}
}
}
因此,成功登录后,expect脚本在发送ls-1t/home/user/
命令之前等待提示。提示可能会有所不同,具体取决于ssh
目标的设置方式。到目前为止,我正在检查
-re "\[%|>|\$|#\] $"
到目前为止已经处理了
%
>
$
#
我希望尽可能地使其通用化,以便我知道目标ssh
服务器已准备好接收ls-1t/home/user/
命令
有没有更好的方法来实现这一点,或者我应该在expect脚本中向reg_ex添加更多案例
我也尝试过-re“$”
,但这不起作用看看您可以使用哪些仅使用shell代码编写Expect脚本。看看您可以使用哪些仅使用shell代码编写Expect脚本。