您现在的位置是:网站首页> 编程资料编程资料
Shell脚本检查IP格式及mysql操作实例_linux shell_
2023-05-26
478人已围观
简介 Shell脚本检查IP格式及mysql操作实例_linux shell_
还是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脚本定期清空大于1G的日志文件_linux shell_
- Shell中函数返回值超出问题_linux shell_
- linux下通过命令行获取gmail的新邮件_linux shell_
- linux下使用rinetd来实现端口转发_linux shell_
- Centos下查看网卡的实时流量命令_linux shell_
- Linux 中 CURL常用命令详解_linux shell_
- 零基础入门篇之Linux及Arm-Linux程序开发笔记_linux shell_
- Linux下使用tcpdump抓包的实现方法_linux shell_
- linux shell 管道命令(pipe)使用及与shell重定向区别_linux shell_
- linux shell数据重定向(输入重定向与输出重定向)详细分析_linux shell_
