使用ssh在linux上安装java

Guy*_*Guy 5 linux ssh bash rpm expect

我想使用ssh在许多计算机上安装java,所以我想编写一个bash脚本(大致):

for c in computers
do    
   scp jre--.rpm $c
   ssh $c 'sudu -s; chmod a+x jre--.rpm ; ./jre--.rpm; echo "success!"'
done
Run Code Online (Sandbox Code Playgroud)

问题是在java安装期间我需要"读取"通知并在结尾处输入"是".我该怎么做?有没有比"期待"更简单的方法?如果不是我如何在bash脚本中使用它?

非常感谢

Guy*_*Guy 1

期望是要走的路(感谢http://www.dnmouse.org/java.html):

   for c in computers
   do    
       scp jre--.rpm $c
       ssh -t $c 'sudo -s; yum -y install expect; sudo chmod a+x jre--.rpm'
       ssh -t $c '/usr/bin/expect -c \
       "set timeout -1; spawn ./jre-6u13-linux-x64-rpm.bin; sleep 1; send -- q\r; sleep 1; send -- yes\r; expect eof"
       echo "success!"'
   done
Run Code Online (Sandbox Code Playgroud)