Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 远程提示需要ssh reg_ex_Linux_Shell_Expect - Fatal编程技术网

Linux 远程提示需要ssh reg_ex

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" {

我有一个shell脚本,它使用expect启动到另一台服务器的ssh会话并列出一个目录。它工作正常,但我的问题是,登录后处理远程提示的最佳方式是什么?例如,以下是我目前掌握的情况:

# 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脚本。