简体   繁体   English

等待来自通过ssh远程运行的脚本的输入

[英]Waiting for input from script that is running remotely via ssh

There is a script I'm running that I can not install on the remote machine. 我正在运行的脚本无法安装在远程计算机上。

clear && printf '\e[3J'
        read -p "Please enter device: " pattern
        read -p "Enter date: (YYYY-MM-DD): " date
        pfix=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 5 | head -n 1)
        mkdir /home/user/logCollectRes/"${pfix}"
        ssh  xxx.xxx.xxx.xxx 'bash -s' < /usr/local/bin/SearchAdvanced.sh ${pattern} ${date} ${pfix}

In that script, I would like to be able to use read. 在该脚本中,我希望能够使用读取。

ls -g *"${pattern}"* 

read -p "Select one of these? [y/n] " "found";

I've tried adding the -n on the read as well as the -t -t option on ssh. 我尝试在读取时添加-n以及在ssh上添加-t -t选项。 As you can see the script presents information that is only seen once the script starts, so I can't use the read on local machine. 如您所见,脚本提供的信息仅在脚本启动后才会显示,因此我无法在本地计算机上使用读取的信息。

EDIT: So lets say server B stores syslogs for 5K computers. 编辑:所以可以说服务器B为5K计算机存储了系统日志。 The file names are given by using the internal IP of the device and the date at the end. 通过使用设备的内部IP和末尾的日期来指定文件名。

/var/log/remotes/192.168.1.500201505050736.gz
/var/log/remotes/192.168.1.500201505050936.gz
/var/log/remotes/192.168.1.500201505051136.gz
/var/log/remotes/192.168.1.600201505050836.gz
/var/log/remotes/192.168.1.600201505051036.gz
/var/log/remotes/192.168.1.600201505051236.gz

I'd like to be able to select the IP address from the main script, list all the files matching that IP address, and then select which I want to scp to my local machine. 我希望能够从主脚本中选择IP地址,列出与该IP地址匹配的所有文件,然后选择要在本地计算机上存储的文件。

After speaking with some coworkers I found the answer to be running two scripts: The first pulls the ls -g result and directs the answer to a variable on the local machine. 与一些同事交谈后,我发现答案正在运行两个脚本:第一个脚本提取ls -g结果并将答案定向到本地计算机上的变量。 I then print that output with the read option of selecting on of the files. 然后,使用选择文件打开的读取选项来打印输出。 The 2nd script will take that answer and scp the file from the remote machine 第二个脚本将获取该答案并从远程计算机中读取文件

In the main script 在主脚本中

ssh  xxx.xxx.xxx.xxx 'bash -s' < /usr/local/bin/SearchAdvanced.sh ${pattern} ${date} > ${result}

then as a follow up 然后作为跟进

printf "${result}"

read -p "Select file: "

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM