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