/dev/nullif [ $ = 1 ]; thenretur" />

广州鸿名健康科技有限公司


Shell脚本检查IP格式及mysql操作实例

网络编程 Shell脚本检查IP格式及mysql操作实例 06-22

还是cronjob的一部分,就是在Rails的定时任务里,后台交互运行

CheckIPAddress()
{
    echo $1 |grep "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$" > /dev/null
    if [ $? = 1 ];  then
        return 1
    else
        a=`echo $1 | awk -F. '{print $1}'`
        b=`echo $1 | awk -F. '{print $2}'`
        c=`echo $1 | awk -F. '{print $3}'`
        d=`echo $1 | awk -F. '{print $4}'`
        #echo $a $b $c $d

        for loop in $a $b $c $d
        do
            if [ $loop -ge 255 ] || [ $loop -lt 0 ]; then
                return 2
            fi
        done
    fi  

}


ConfigureDefaultRegion() {
  echo "Please input Region ip"
  ret=1
  while [ $ret != 0 ]
  do
   read region_ip
   CheckIPAddress $region_ip
   ret=$?
   #echo $ret
   if [ $ret = 1 ]; then
    echo "Wrong IP address, please reinput Region IP:"
   fi
  done
  /usr/bin/mysql -u root realworx_production -e "update regions set ip='$region_ip' where id=1" 1>/dev/null 2>/dev/null
  if [ $? = 0 ]; then
          /usr/bin/mysql -u root realworx_production -e "update config_params set val=1 where ident=55" 1>/dev/null 2>/dev/null
          echo "set '$region_ip' as Default and Admin Region IP"
  else
          val=`/usr/bin/mysql -u root realworx_production -e "select id from regions where ip='$region_ip'" | awk '{if ($1 != "id") print $1}'`
          /usr/bin/mysql -u root realworx_production -e "update config_params set val='$val' where ident=55" 1>/dev/null 2>/dev/null
          region_name=`/usr/bin/mysql -u root realworx_production -e "select name from regions where ip='$region_ip'" | awk '{if ($1 != "name") print $1}'`
          echo "IP already exists. So set '$region_name' as Admin Region. "
  fi
  echo "Region Setting Successfull."
}

Shell正则表达式验证IP地址
本机多个IPifconfig|awk'/inet/{print$2}'|awk-F:'{print$2}'首先,先用这个来着CheckIPAddress(){echo$1/tmp/tmpserveripecho$1|grep"^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"/dev

Centos下查看网卡的实时流量命令
可以通过iptraf命令查看网卡的实时流量,图像非常直观。今天在测试服务器上准备看下网络流量[root@localhost~]#iptraf-deth0-bash:iptraf:commandnotfound发现运维同

linux下使用rinetd来实现端口转发
windows下的端口转发一般用的是自带的nat和porttunnel、portmaplinux下端口转发映射的程序叫rinetd,启动方法rinetd-c/etc/rinetd.conf,pkillrinetd关闭进程工具主页:htt


编辑:广州鸿名健康科技有限公司

标签:端口,网卡,实时,的是,流量