Shell脚本检查IP格式及mysql操作实例
(编辑:jimmy 日期: 2024/12/27 浏览:3 次 )
还是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 [ $"Please input Region ip" ret=1 while [ $ret != 0 ] do read region_ip CheckIPAddress $region_ip ret=$"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 [ $"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." }
下一篇:Linux Shell脚本系列教程(六):数组和关联数组