1

I have some commands to prompt for yes or no answer in my script, but the read answer command (interactive mode) not working, while running the script using ssh bash -s script.

ssh user@hostname bash -s < "/home/xxxx/devstop.sh"

it is not prompting the question from remote shell and exits to the source shell.

My script :

if [ "$count" -eq "0" ]
then
        echo -e "${GREEN}Tomcat Server stopped successfully on '$HOSTNAME' ${NC}"
elif [ $count -gt "0" ]
then 
        echo -e "${RED}Tomcat Server not stopped on '$HOSTNAME' please check it ${NC}"
        echo "Do you want to continue all the tomcat server shutdown process in -`date` "
echo "          Please Read the Above and Enter (Y/N) to Proceed or Stop to cancel shutdown processes :  \c"
read answer

value=`echo ${answer} | tr -s '[:lower:]' '[:upper:]'`

if [ "$value" = "Y" ]
then
        echo "                             Remaining tomcat Services are going down."
else
        echo "                             Cancelled tomcat Services shutdown process in '$HOSTNAME."
        exit 1;
fi

fi

ps -ef|grep tomcat|grep -v grep |grep -i "catalina.startup.Bootstrap start"

exit
1

1 Answer 1

1

The read works. But differently from what you think.

ssh user@hostname bash -s < "/home/xxxx/devstop.sh"

This tells ssh user@hostname bash -s to get its stdin from the file devstop.sh. So when it comes up to your

read answer

It will take the next line from stdin as input for the read. In your script, this is an empty line. Because of the empty line, your answer will be empty.

You can test this locally:

$ cat <<EOF >it
read a
echo $a
echo $a
EOF
$ bash it
q
q
q
$ bash < it
echo $a

The first q is the keyboard input.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.