主頁 > 知識庫 > Shell腳本檢查IP格式及mysql操作實例

Shell腳本檢查IP格式及mysql操作實例

熱門標(biāo)簽:呼叫中心市場需求 鐵路電話系統(tǒng) 網(wǎng)站排名優(yōu)化 AI電銷 地方門戶網(wǎng)站 服務(wù)外包 百度競價排名 Linux服務(wù)器

還是cronjob的一部分,就是在Rails的定時任務(wù)里,后臺交互運行

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下實現(xiàn)免密碼快速登陸MySQL數(shù)據(jù)庫的方法
  • MySQL數(shù)據(jù)庫的shell腳本自動備份
  • Centos7安裝 mysql5.6.29 shell腳本
  • MySQL5.7安裝過程并重置root密碼的方法(shell 腳本)
  • 實戰(zhàn)模擬監(jiān)控MySQL服務(wù)shell腳本小結(jié)
  • MySQL的一些功能實用的Linux shell腳本分享
  • CentOS下編寫shell腳本來監(jiān)控MySQL主從復(fù)制的教程
  • shell腳本自動修復(fù)mysql損壞的表
  • linux下mysql如何自動備份shell腳本
  • 一個簡單的MySQL備份Shell腳本
  • 用shell寫一個mysql數(shù)據(jù)備份腳本

標(biāo)簽:蘭州 銅川 黃山 湘潭 湖南 崇左 仙桃 衡水

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Shell腳本檢查IP格式及mysql操作實例》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266