從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簡單腳本