栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

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

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

还是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."
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/37525.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号