首页 > 代码库 > linux 拨号+squid监控脚本
linux 拨号+squid监控脚本
客户端
#!/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 5 -c 1 114.114.114.114 > /dev/null 2>&1 if [ $? -eq 0 ];then net_status="0" else net_status="1" 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="0" else squid_status_code="1" fi #echo $squid_status_code echo "\"memory\":\""$mem_percent"\",\""net_status\":\""$net_status"\",\""squid_status\":\""$squid_status_code"\""
服务端:
#!/bin/bash machine_ip=$1 machine_port=$2 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=6 -p $machine_port root@$machine_ip ‘sh /root/get_machine_info.sh‘` len=`echo $machine_status|wc -c` if [ $len -gt 10 ];then echo $machine_status > /tmp/.$f1.txt else echo "\"memory\":\""1"\",\""net_status\":\""1"\",\""squid_status\":\""1"\"" > /tmp/.$f1.txt fi }& { #echo "get wan ip" host=`ssh -o ConnectTimeout=3 -p $machine_port root@$machine_ip ‘sh /root/get_wan_ip.sh‘|awk -F: ‘{print$1}‘` #echo $host #ssh -o ConnectTimeout=3 root@$host "date" > /dev/null #echo "test wan ip for 22" ping -W 3 -c 1 $host > /dev/null 2>&1 if [ $? -eq 0 ];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=3 -p $machine_port root@$machine_ip ‘sh /root/get_wan_ip.sh‘` if [ $? -eq 0 ] && [ "$proxy_ip_port" != "null" ];then #echo "get curl result" result=`curl -I -m 5 -x $proxy_ip_port -o /dev/null -s -w %{http_code} map.baidu.com` if [ $result -eq 200 ];then proxy_ip_port_status=`echo "\"proxy_ip\":\"0\",\""proxy_port\":\"0\"` else #echo "get wan ip" #host=`ssh -o ConnectTimeout=3 -p $machine_port root@$machine_ip ‘sh /root/get_wan_ip.sh‘|awk -F: ‘{print$1}‘` #ssh -o ConnectTimeout=3 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` while (($f3v < 4)) 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"}"
linux 拨号+squid监控脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。