我的项目的战争(相同)部署在不同的服务器上,我想从一些jsp页面刷新缓存......
基本上我想...... 从.sh文件中的wget命令远程命中一些url。 (my.sh)
我试过......
如果我执行
wget http://localhost:8080/someDirectory/refreshSomePage.jsp
单个服务器上的...它将点击服务器并刷新页面....
在.sh文件中我这样做了:
#!/bin/bash
declare -a _servers=('192.168.1.1' '192.168.1.2' '192.168.1.3' '192.168.1.4')
for ((i=0;i<${#_servers[@]};i++));
do
echo "-------- Server: ${_servers[i]} ---------"
ssh myUser@${_servers[i]} < wget http://localhost:8080/someDirectory/refreshSomePage.jsp
echo "-------- Complete ---------"
done
但会得到以下结果:
-------- Server: 192.168.1.1 ---------
my.sh: line 11: wget http://localhost:8080/someDirectory/refreshSomePage.jsp: No such file or directory
-------- Complete ---------
-------- Server: 192.168.1.2 ---------
my.sh: line 11: wget http://localhost:8080/someDirectory/refreshSomePage.jsp: No such file or directory
-------- Complete ---------
-------- Server: 192.168.1.3 ---------
my.sh: line 11: wget http://localhost:8080/someDirectory/refreshSomePage.jsp: No such file or directory
-------- Complete ---------
-------- Server: 192.168.1.4 ---------
my.sh: line 11: wget http://localhost:8080/someDirectory/refreshSomePage.jsp: No such file or directory
-------- Complete ---------
如何解决这个问题?
答案 0 :(得分:1)
我猜你的错误是使用不必要的管道符号。您也可以从localhost下载,localhost是每个服务器本身的本地主机。
所以试试这个:
#!/bin/bash
declare -a _servers=('192.168.1.1' '192.168.1.2' '192.168.1.3' '192.168.1.4')
ORIGIN = "192.168.1.254"
for ((i=0;i<${#_servers[@]};i++));
do
echo "-------- Server: ${_servers[i]} ---------"
ssh myUser@${_servers[i]} wget http://${ORIGIN}:8080/someDirectory/refreshSomePage.jsp
echo "-------- Complete ---------"
done
我希望您使用基于ssh密钥的授权来避免将来的输入。