Shell腳本檢查IP格式及mysql操作實(shí)例
更新時(shí)間:2015年05月26日 11:29:37 投稿:junjie
這篇文章主要介紹了Shell腳本檢查IP格式及mysql操作實(shí)例,本文直接給出腳本代碼,需要的朋友可以參考下
還是cronjob的一部分,就是在Rails的定時(shí)任務(wù)里,后臺(tái)交互運(yùn)行
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下實(shí)現(xiàn)免密碼快速登陸MySQL數(shù)據(jù)庫(kù)的方法
- MySQL數(shù)據(jù)庫(kù)的shell腳本自動(dòng)備份
- Centos7安裝 mysql5.6.29 shell腳本
- MySQL5.7安裝過程并重置root密碼的方法(shell 腳本)
- 實(shí)戰(zhàn)模擬監(jiān)控MySQL服務(wù)shell腳本小結(jié)
- MySQL的一些功能實(shí)用的Linux shell腳本分享
- CentOS下編寫shell腳本來(lái)監(jiān)控MySQL主從復(fù)制的教程
- shell腳本自動(dòng)修復(fù)mysql損壞的表
- linux下mysql如何自動(dòng)備份shell腳本
- 一個(gè)簡(jiǎn)單的MySQL備份Shell腳本
- 用shell寫一個(gè)mysql數(shù)據(jù)備份腳本
相關(guān)文章
阿里云云服務(wù)器Linux系統(tǒng)更新yum源Shell腳本
這篇文章主要介紹了阿里云云服務(wù)器Linux系統(tǒng)更新yum源Shell腳本,阿里云自建了一個(gè)包含大多數(shù)系統(tǒng)更新的本地yum源,速度快又好用,需要的朋友可以參考下2014-09-09
Linux使用curl訪問網(wǎng)頁(yè)和wget下載文件
這篇文章介紹了Linux使用curl命令訪問網(wǎng)頁(yè)和wget下載文件的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
shell腳本批量創(chuàng)建用戶的方法小結(jié)
有些面試題中會(huì)問到批量創(chuàng)建用戶的題目,大體是用循環(huán)去進(jìn)行創(chuàng)建,但有時(shí)也會(huì)有一些額外的附加條件,下面這篇文章主要給大家介紹了關(guān)于shell腳本批量創(chuàng)建用戶的相關(guān)資料,需要的朋友可以參考下2022-03-03
一天一個(gè)shell命令 linux文本內(nèi)容操作系列-sed命令詳解
這篇文章主要介紹了一天一個(gè)shell命令 linux文本內(nèi)容操作系列-sed命令詳解,需要的朋友可以參考下2016-06-06
ssh,scp自動(dòng)登陸的實(shí)現(xiàn)方法
這篇文章主要介紹ssh,scp自動(dòng)登陸的實(shí)現(xiàn)方法,需要的朋友可以參考下2013-02-02
Shell常見知識(shí) 方便想學(xué)習(xí)linux shell的彭玉
本文給大家介紹了一些Shell小知識(shí),供參考學(xué)習(xí)2013-01-01

