客户端
#!/bin/bash #get_memory-info a=`free -m|grep Mem|awk '{print$2}'` #total-memory b=`free -m|grep Mem|awk '{print$3}'` #used-memory mem_percent=`awk 'BEGIN{printf "%.2f%\n",('$b'/'$a')*100}'` #used-memory-% #echo $mem_percent #get_network_info ping -W -c >& ];then net_status=" else net_status=" fi #echo $net_status #get_squid_process_status squid_status=`systemctl status squid|grep Active|awk '{print$2}'` if [ "$squid_status" = "active" ];then squid_status_code=" else squid_status_code=" fi #echo $squid_status_code echo "\"memory\":\""$mem_percent"\",\""net_status\":\""$net_status"\",\""squid_status\":\""$squid_status_code"\""
服务端:
#!/bin/bash machine_ip=$ machine_port=$ f1=`cat /proc/sys/kernel/random/uuid` f2=`cat /proc/sys/kernel/random/uuid` f3=`cat /proc/sys/kernel/random/uuid` rm -rf /tmp/.$f1.txt /tmp/.$f2.txt /tmp/.$f3.txt touch /tmp/.$f1.txt /tmp/.$f2.txt /tmp/.$f3.txt { #echo "get machine_status" machine_status=`ssh -o ConnectTimeout= -p $machine_port root@$machine_ip 'sh /root/get_machine_info.sh'` len=`echo $machine_status|wc -c` ];then echo $machine_status > /tmp/.$f1.txt else echo "\"" > /tmp/.$f1.txt fi }& { #echo "get wan ip" host=`ssh -o ConnectTimeout= -p $machine_port root@$machine_ip 'sh /root/get_wan_ip.sh'|awk -F: '{print$1}'` #echo $host #ssh -o ConnectTimeout= root@$host "date" > /dev/null #echo "test wan ip for 22" ping -W -c $host > /dev/>& ];then #proxy_ip_port_status=`echo "\"proxy_ip\":\"0\",\""proxy_port\":\"1\"` echo "\"proxy_ip\":\"0\",\""proxy_port\":\"1\" > /tmp/.$f3.txt else #proxy_ip_port_status=`echo "\"proxy_ip\":\"1\",\""proxy_port\":\"0\"` echo echo "\"proxy_ip\":\"1\",\""proxy_port\":\"1\" > /tmp/.$f3.txt fi }& { #echo "get proxy_ip_port" proxy_ip_port=`ssh -o ConnectTimeout= -p $machine_port root@$machine_ip 'sh /root/get_wan_ip.sh'` ] && [ "$proxy_ip_port" != "null" ];then #echo "get curl result" result=`curl -I -m -x $proxy_ip_port -o /dev/null -s -w %{http_code} map.baidu.com` ];then proxy_ip_port_status=`echo "\"proxy_ip\":\"0\",\""proxy_port\":\"0\"` else #echo "get wan ip" #host=`ssh -o ConnectTimeout= -p $machine_port root@$machine_ip 'sh /root/get_wan_ip.sh'|awk -F: '{print$1}'` #ssh -o ConnectTimeout= root@$host "date" > /dev/null #echo "test wan ip for 22" #if [ $? -eq 0 ];then # proxy_ip_port_status=`echo "\"proxy_ip\":\"0\",\""proxy_port\":\"1\"` #else # proxy_ip_port_status=`echo "\"proxy_ip\":\"1\",\""proxy_port\":\"0\"` #fi f3v=`cat /tmp/.$f3.txt|wc -c` )) do f3v=`cat /tmp/.$f3.txt|wc -c` done proxy_ip_port_status=`cat /tmp/.$f3.txt` fi else proxy_ip_port_status=`echo "\"proxy_ip\":\"1\",\""proxy_port\":\"1\"` fi echo $proxy_ip_port_status > /tmp/.$f2.txt }& wait proxy_ip_port_status=`cat /tmp/.$f2.txt` machine_status=`cat /tmp/.$f1.txt` rm -rf /tmp/.$f1.txt /tmp/.$f2.txt /tmp/.$f3.txt #echo $machine_status #echo $proxy_ip_port_status echo "{"$machine_status","$proxy_ip_port_status"}"