2015年5月11日 星期一

shell 抓 ip

arg=`ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
ipaddr=$arg
echo $ipaddr



#!/bin/bash
old_ipaddr="0.0.0.0";
connect_status="Unknown!";

while [ 1 ]
do
  process=`ps aux | grep udhcpc | grep -v grep`;
  process="";
  if [ "$process" == "" ]; then
        process=`ps aux | grep http | grep -v grep`;
        if [ "$process" == "" ]; then
           net_status=`ethtool eth0 | grep "Speed" | cut -f 2 -d " "`
           echo "haha__$net_status"
           if [ "$net_status" != "Unknown!" ]; then
                ipaddr=`ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`          
                if [ "$connect_status" == "Unknown!" ]; then
                      connect_status=$net_status;
                      ret=`/usr/sbin/notify_ip_change.php eth0`;
                      echo "haha request slave send config 0" 
                else       
                    if [ "$ipaddr" != "$old_ipaddr" ]; then
                      ret=`/usr/sbin/notify_ip_change.php eth0`;
                      echo "haha request slave send config 1" 
                    fi   
                fi
                old_ipaddr=$ipaddr;
           else
                connect_status="Unknown!";
           fi
        else
          old_ipaddr="0.0.0.0";
          connect_status="Unknown!";
        fi
  else
    old_ipaddr="0.0.0.0";
    connect_status="Unknown!";
  fi

  sleep 3 
done


沒有留言:

張貼留言