通过NSH获取被管服务器属性信息
通过该方法可以把服务器配置信息输出为CSV文件.
注:脚本可执行的前提是你已经配置了blcli环境.
?
?
1. 创建服务器列表文件
?
# cat servers.txtserver1server2server3server4server5?
?
2. 创建配置属性文件
?
# cat propertiesASSET_IDASSET_TAGCABINETWARRANTY_EXPIRATIONREMOTE_ACCESS_NAMEENVIRONMENTDR_REQUIREMENTSPATCH_GROUPSITEASSET_MANAGERAIT_SUPPORT_ROLEOWNERDIVISIONAL_CONTACTDEPARTMENTMAINTENANCE_WINDOWITEM?
?
3. 创建脚本文件
?
#!/usr/nsh/bin/nsh if [ 2 -ne $# ]then echo "usage: $0 full_path_to_list_of_servers full_path_to_list_of_properties" exitfi if [ ! -e "$1" ] || [ ! -e "$2" ]then echo "can't find either $1 or $2" exitfi SERVERFILE="$1"TAGSFILE="$2"date >&2echo "using $SERVERFILE for the list of servers" >&2echo "using $TAGSFILE for the list of properties" >&2 VALIDTAGS=""validate_tags () { blcli_execute PropertySetClass getAllPropertyNames Class://SystemObject/Server > /dev/null 2>&1 blcli_storeenv thetags for i in `cat "$TAGSFILE" |tr -d '\015'| sort` do echo "$thetags" | grep $i >/dev/null 2>&1 if [ 0 -eq $? ] then VALIDTAGS=`echo "$VALIDTAGS""|""^$i"` fi done VALIDTAGS=`echo "$VALIDTAGS" | sed -e 's/^|\(.*\)/\1/'`} echo "connecting" >&2blcli_connectif [ $? -ne 0 ]then echo "can't connect blcli" exitfiecho "connected." >&2 echo "validating the list of properties" >&2validate_tags if [ -z "$VALIDTAGS" ]then echo "no parameter is valid" exitelse echo "the following properties are valid:"`echo "$VALIDTAGS" | tr '|' ','` | tr -d ^ >&2fi echo "processing list of servers" >&2echo "server,""`echo "$VALIDTAGS" | tr '|' ',' | tr -d ^`"for server in `cat $SERVERFILE | tr -d '\015'`do blcli_execute Server printAllProperties $server > /dev/null 2>&1 if [ $? -eq 0 ] then blcli_storeenv theinstance echo -n "$server""," echo "$theinstance" | grep -E "$VALIDTAGS" | sort | cut -d '=' -f 2 | awk 'BEGIN {ORS=",";} {print $0}' | sed -e 's/\(.*\),$/\1/' echo "" fidoneblcli_disconnect date >&2echo "done" >&2
?
?
4. 脚本执行及输出
?
# nsh get_properties_for_servers.nsh 5servers.txt properties > sample_output.csvWed Oct 8 05:33:39 EDT 2008using servers.txt for the list of serversusing properties for the list of propertiesconnectingconnected.validating the list of propertiesthe following properties are valid:ASSET_ID,ENVIRONMENT,MAINTENANCE_WINDOW,PATCH_GROUPprocessing list of serversWed Oct 8 05:33:47 EDT 2008done suprhas30serv1# cat sample_output.csvserver,ASSET_ID,ENVIRONMENT,MAINTENANCE_WINDOW,PATCH_GROUPserver1, AST0047093, Test Lab, Sunday 12:00 a.m. - 4:00 a.m., EUT - TESTserver2, AST0047107, Test Lab, Sunday 12:00 a.m. - 4:00 a.m., EUT - TESTserver3, AST0047120, Test Lab, Sunday 12:00 a.m. - 4:00 a.m., EUT - TESTserver4, AST0047177, Test Lab, Sunday 12:00 a.m. - 4:00 a.m., EUT - TESTserver5, AST0047122, Test Lab, Sunday 12:00 a.m. - 4:00 a.m., EUT - TEST