我的腳本中有一些命令提示是或否答案,但在使用ssh bash -s script
.
ssh user@hostname bash -s < "/home/xxxx/devstop.sh"
它不會從遠端 shell 提示問題並退出到來源 shell。
我的腳本:
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
作品read
。但和你想的不一樣。
ssh user@hostname bash -s < "/home/xxxx/devstop.sh"
這告訴ssh user@hostname bash -s
我們從文件中獲取它的標準輸入devstop.sh
。所以當涉及到你的
read answer
它將把 stdin 中的下一行作為read
.在您的腳本中,這是一個空行。由於空行,您的答案將為空。
您可以在本地測試:
$ cat <<EOF >it
read a
echo $a
echo $a
EOF
$ bash it
q
q
q
$ bash < it
echo $a
第一個q
是鍵盤輸入。