## 130.75.131.246 机器 ### 130.75.131.246 编写startweb.sh ,让130.75.131.245机器通过startotherweb.sh远程调用 vi startweb.sh ``` #!/bin/bash # cd /root/webapps/eureka-server/bin case $1 in 'start') ./start.sh && echo "start server......." ;; 'stop') ./stop.sh && echo "stop server .......";; 'restart') ./stop.sh && ./start.sh && echo "restart server .......";; *) echo "`basename $0` {start|stop|restart|status}";; esac ``` cat 查看 ``` [root@localhost bin]# cat startweb.sh #!/bin/bash # case $1 in 'start') ./start.sh && echo "start server......." ;; 'stop') ./stop.sh && echo "stop server .......";; 'restart') ./stop.sh && ./start.sh && echo "restart server .......";; *) echo "`basename $0` {start|stop|restart|status}";; esac ``` ## 130.75.131.245 配置文件 vi startotherweb.ini ``` root:130.75.131.246:/root/webapps/eureka-server/bin/startweb.sh ``` cat 查看 ``` [root@localhost ~]# cat startotherweb.ini root:130.75.131.246:/root/webapps/eureka-server/bin/startweb.sh ``` ## 130.75.131.245 startotherweb.sh vi startotherweb.sh ``` #!/bin/bash for rec in `cat /root/startotherweb.ini|grep -v "#"` do USERNAME=`echo $rec |awk -F: '{ print $1 }'` DES_IP=`echo $rec |awk -F: '{ print $2 }'` EXE_FILE_PATH=`echo $rec |awk -F: '{ print $3 }'` nohup ssh $USERNAME@${DES_IP} " ${EXE_FILE_PATH} $@ " & #ssh $USERNAME@${DES_IP} " ${EXE_FILE_PATH} $@ " done ``` cat 查看 ``` [root@localhost ~]# cat startotherweb.sh #!/bin/bash for rec in `cat /root/startotherweb.ini|grep -v "#"` do USERNAME=`echo $rec |awk -F: '{ print $1 }'` DES_IP=`echo $rec |awk -F: '{ print $2 }'` EXE_FILE_PATH=`echo $rec |awk -F: '{ print $3 }'` nohup ssh $USERNAME@${DES_IP} " ${EXE_FILE_PATH} $@ " & #ssh $USERNAME@${DES_IP} " ${EXE_FILE_PATH} $@ " done ``` ## 远程执行 ``` ./startotherweb.sh start ``` 一键启停脚本 ``` [root@localhost ~]# ./startotherweb.sh stop [root@localhost ~]# ./startotherweb.sh restart [root@localhost ~]# ./startotherweb.sh stop [root@localhost ~]# ./startotherweb.sh start ```