码迷,mamicode.com
首页 > 数据库 > 详细

从CMDB查询云平台组件或者IP简单脚本

时间:2018-05-15 01:46:35      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:bash   pen   echo   脚本   die   from   简单脚本   mysql   $*   

#!/bin/bash
#author xiaoweige
#todo: ip -- > ingredient or ingredient -- > ip

#todo: get the ip of the given ingredient
function ingredient_ip() {
#todo: get the ip of the ingredient given
  mysql -uroot -pengine -e "select * from ipandingredient.ipandingredient where env =‘$1‘ and ingredient=‘$2‘"
}
#todo: not sure what the ingredient is
function search_ingredient() {
  mysql -uroot -pengine -e "use ipandingredient ;select * from ipandingredient where ingredient like ‘%${1}%‘ "

}
#todo: get the ip of the ingredient given
function ip_ingredient() {
  mysql -uroot -pengine -e "use ipandingredient; select * from ipandingredient where env=‘$1‘ and ip=‘$2‘ "

}

function usage() {
  echo "to get ingredient USAGE: ./$0 ip"
  echo "to get ip USAGE: ./$0 ingredient"
  echo "search ingredient ./$0 sth"

}

function main(){
  if [ $# -eq 0 ]
  then
    usage
  elif [ $# -eq 1 ]
  then
    search_ingredient $1
  elif [ $# -eq 2 ]
  then
  argtype=`echo $2|egrep [1-9+\.]`
  if [ -z $argtype ]
  then
    ingredient_ip $1 $2
  else
    ip_ingredient_ip $1 $2
  fi
fi

}
main $*

从CMDB查询云平台组件或者IP简单脚本

标签:bash   pen   echo   脚本   die   from   简单脚本   mysql   $*   

原文地址:https://www.cnblogs.com/hixiaowei/p/9038862.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!