从CMDB查询云平台组件或者IP简单脚本
Posted littlevigra
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从CMDB查询云平台组件或者IP简单脚本相关的知识,希望对你有一定的参考价值。
#!/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简单脚本的主要内容,如果未能解决你的问题,请参考以下文章