Shell script check IP format and MySQL operation instance

Source: Internet
Author: User

This article mainly introduced the shell script to check the IP format and MySQL operation instance, this article directly gives the script code, needs the friend may refer to under

Or part of the cronjob, which is the background interaction running in the Rails timing task

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the ; > Checkipaddress () {echo $ |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 $ | Awk-f. ' {print} ' b= ' echo $ | Awk-f. ' {print $} ' c= ' echo $ | Awk-f. ' {print $} ' d= ' echo $ | Awk-f. ' {print $} ' #echo $a $b $c $d   for loops in $a $b $c $d do if [$loop-ge 255] | | [$loop-lt 0]; Then return 2 fi do fi  }     Configuredefaultregion () {echo ' Please input Region IP ' ret=1 while [$re T!= 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 Regi ONS set ip= ' $region _ip ' where id=1 ' 1>/dev/null/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>/de V/null echo "Set" $region _ip ' as Default and Admin region IP ' else val= '/usr/bin/mysql-u root realworx_production-e ' sel ECT ID from regions where ip= ' $region _ip ' | awk ' {if (!= id) print ' {} '/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 Regi ONS where ip= ' $region _ip ' | awk ' {if (!= ' name ') print ' echo ' IP already exists. So set ' $region _name ' as Admin region. "Fi echo" Region Setting successfull. "}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.