Shell脚本检查IP格式及mysql操作实例
2015-05-26 00:00
746 查看
还是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." }
相关文章推荐
- Shell脚本检查IP格式及mysql操作实例
- Shell脚本中执行sql语句操作mysql的5种方法
- Shell脚本实现检查服务器安全状态(用户、登录IP、防火墙检查)
- shell 操作mysql保存数据脚本 demo
- 在 shell 脚本获取 ip、数字转换等网络操作
- shell脚本实现简单的模拟用户操作,未加检查点。
- Shell脚本连接、读写、操作mysql数据库实例
- 输出执行操作和打印日志的shell脚本实例
- 自动检查MySQL主从同步状态的shell脚本
- shell脚本操作mysql数据库,使用mysql的-e参数可以执行各种sql的(创建,删除,增,删,改、查)等各种操作
- shell脚本建多库、多表、多实例(mysql)
- [实例]利用php+mysql完成shell脚本的授权验证
- PHP+shell脚本操作Memcached和Apache Status的实例分享
- Shell脚本中执行sql语句操作mysql
- shell监控脚本实例―监控mysql主从复制
- 使用shell脚本操作mysql
- shell脚本连接、读写、操作mysql数据库实例
- shell脚本连接、读写、操作mysql数据库实例
- Shell脚本中执行sql语句操作mysql
- Shell脚本中执行sql语句操作mysql的5种方法