运行脚本以SSH进入主机,收集用户输入并将信息发送回原始主机。无法获得用户输入

时间:2018-09-26 15:43:07

标签: input ssh user-input

我目前正在处理一个脚本,该脚本应该执行以下操作:

-通过SSH进入远程主机

-切换到SU

-获取所有转储记录的列表

-选择转储记录以编译成日志

这是我最初使用的:

#!/bin/bash
# Get IP address to SSH into
echo Enter Device IP
read vardeviceip

# Remote into Device
ssh -t support@$vardeviceip << EOF

## AFTER LOGIN

# Switch to root
sudo su

# Check number of system boots recorded by journalctl
journalctl --list-boots

# Ask user for which set to get
echo Enter index number you wish to retrieve
read varindexnum

# Compile logs
nohup collect-diag -t collect_all_logs -s oldest_boot=$varindexnum

# List compiled logs and ask user for which log to download
ls -l /var/log/device/dump/
echo Enter timestamp of log to be downloaded
read varlogtimestamp

# Log out of Device
bash -l

EOF

运行脚本时,我可以SSH登录,但是未执行“读取”命令。这是为什么?我该怎么做才能解决此问题?

谢谢!

1 个答案:

答案 0 :(得分:0)

好的,我找到了。我必须制作第二个Shell脚本并在第一个脚本中运行它,如下所示:

ssh -t support@$vardeviceip "$(cat getlogs.sh)"

仍然感谢!