在远程linux服务器上运行bash脚本时无法接受用户输入

时间:2019-05-31 13:28:12

标签: linux bash shell

我是bash脚本的新手。 我正在从server1运行bash脚本,该脚本将SSH到远程服务器并在其上运行脚本。 该远程脚本需要有一些用户输入,但是当我运行脚本时,它会绕过用户输入。 我能够SSH到远程服务器并运行命令(已经测试了诸如“主机名”和“ cd”之类的简单命令,但是用户输入部分无法正常工作。

下面是详细信息,感谢您的帮助。

server1上的脚本:

#!/bin/bash

ssh -q -oStrictHostKeyChecking=no “remote_server” sudo su - root << EOF

bash <(curl -sk http://jumpserver/pub/bootstrap/menutest.sh)

EOF

在这里:jumpserver允许我在环境中的所有服务器上运行脚本。 Menutest.sh是我需要在远程服务器上运行的脚本

远程服务器上的脚本:menutest.s

#!/bin/bash

echo "you are now logged in to server "  ``hostname``

cd /local/log/

echo “ you are now in location” `pwd`

# read the date from user ( this is the date from which user wants to read the file from

echo "Enter the date to read to data ( please provide date only till last 7 days) : "

read n1

echo "the date you entered is $n1"


#extract the file based on the date entered by user


file=$(/usr/bin/ls /local/log | grep -i log | grep -i $n1)


echo " the log file from" $n1 " is " $file


#read the time for which the user needs the information from in that  log file


echo "Enter the time to read to data ( please provide time in hh:mm format with 5 mins interval ( eg 05:35, 13:45 etc) : "


read n2

echo " the time you entered is $n2"

cpu_mem_data=$(cat $file |  grep $n2 -A 30)


echo "$cpu_mem_data"

这是来自server1的脚本运行的输出:

enter the server name

cvmlnx0091

server chosen is cvmlnx0091

Enter the date to read to data ( please provide date only till last 7 days) :

24

the date you entered is 24

Enter the time to read to data ( please provide time in hh:mm format with 5 mins interval ( eg 05:35, 13:45 etc) :

14:15

the time you entered is 14:15

you are now logged in to server  CVMLNX0091

/local/log

Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
the log file from  is
reading data from it......
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.

我在这里做错了什么?

0 个答案:

没有答案