Shell指令碼檢查IP格式及mysql操作執行個體_linux shell

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.