ssh远程调用脚本curl到外网无法连接
来源: 互联网 发布时间:2017-04-11
本文导语: 求大神指导,写了linux监控服务器负载的shell脚本,单独运行都没有任何问题,就是连续ssh到三台机子有时就会出现无法连接的错误,有时候要90多秒才能连上 ssh webgroup@"192.168.2.122" "/bin/sh /home/webgroup/balancing.sh;exit" ...
求大神指导,写了linux监控服务器负载的shell脚本,单独运行都没有任何问题,就是连续ssh到三台机子有时就会出现无法连接的错误,有时候要90多秒才能连上
ssh webgroup@"192.168.2.122" "/bin/sh /home/webgroup/balancing.sh;exit"
ssh liujin@"192.168.2.180" "/bin/sh /home/liujin/balancing.sh;exit"
ssh dbuser@"192.168.2.126" "/bin/sh /home/dbuser/balancing.sh;exit"
下面是balancing.sh脚本的代码
ssh webgroup@"192.168.2.122" "/bin/sh /home/webgroup/balancing.sh;exit"
ssh liujin@"192.168.2.180" "/bin/sh /home/liujin/balancing.sh;exit"
ssh dbuser@"192.168.2.126" "/bin/sh /home/dbuser/balancing.sh;exit"
下面是balancing.sh脚本的代码
#!/bin/sh
ip=`/sbin/ifconfig |grep addr:192|awk '{print $2}'|cut -b 6-`
up=`uptime`
data=`echo ${up#*'average:'}|awk '{print $1}'|sed 's/,*//g'`
paras=$(echo [{"name":"balance","data":"${data}"}])
(curl -S --connect-timeout 10 --retry 20 -d "paras=${paras}&type=4&ip=${ip}" http://218.108.34.254:8060/monitor/monitor!save.action )&
|
ssh webgroup@"192.168.2.122" "/bin/sh /home/webgroup/balancing.sh;exit" &
ssh liujin@"192.168.2.180" "/bin/sh /home/liujin/balancing.sh;exit" &
ssh dbuser@"192.168.2.126" "/bin/sh /home/dbuser/balancing.sh;exit" &