根据内存大小自动匹配和绑定自动伸缩策略【shell】
#!/bin/bash for x in $(cf a|grep started|tr -s " " |cut -d " " -f 1) do ins_quantity=$(cf a|grep $x|tr -s " "|cut -d " " -f 3|cut -d "/" -f 2); app_memory=$(cf a|grep $x|tr -s " "|cut -d " " -f 4); echo "appname:"$x echo "instance num:"${ins_quantity}; unit_suffix=`echo ${app_memory: -1}`; if [[ $unit_suffix == "G" ]];then app_memory_num=`echo ${app_memory%G*}`; elif [[ $unit_suffix == "M" ]];then app_memory_num=`echo ${app_memory%M*}`; else echo "ERROS: unit_suffix get fail!" exit 1; fi echo "app_memory num:"${app_memory_num}; echo "unit_suffix:"${unit_suffix}; strategy_name="" case $app_memory_num in 512) strategy_name="m0.5c25" ;; 1) strategy_name="m1c50" ;; 1.5) strategy_name="m1.5c75" ;; 2) strategy_name="m2c100" ;; 2.5) strategy_name="m2.5c125" ;; 3) strategy_name="m3c150" ;; 3.5) strategy_name="m3.5c175" ;; 4) strategy_name="m4c200" ;; esac echo "strategy_name:"$strategy_name if [[ $ins_quantity -ge 2 && $strategy_name != "" ]];then echo "aspt bind -a "$x" -p "$strategy_name" -e true"; aspt bind -a $x -p $strategy_name -e true; else echo "appanme:"$x " is not set auto scale ! because ins num too small!" fi; done