NSH를 통해 관리되는 서버 속성 정보 얻기

4163 단어 서버
이 방법을 통해 서버 설정 정보를 CSV 파일로 출력할 수 있습니다.
주: 스크립트가 실행될 수 있는 전제 조건은blcli 환경을 설정한 것입니다.
 
 
1. 서버 목록 파일 만들기
 
# cat servers.txt
server1
server2
server3
server4
server5
 
 
2. 구성 속성 파일 만들기
 
# cat properties
ASSET_ID
ASSET_TAG
CABINET
WARRANTY_EXPIRATION
REMOTE_ACCESS_NAME
ENVIRONMENT
DR_REQUIREMENTS
PATCH_GROUP
SITE
ASSET_MANAGER
AIT_SUPPORT_ROLE
OWNER
DIVISIONAL_CONTACT
DEPARTMENT
MAINTENANCE_WINDOW
ITEM
 
 
3. 스크립트 파일 만들기
 
#!/usr/nsh/bin/nsh
 
if [ 2 -ne $# ]
then
  echo "usage: $0 full_path_to_list_of_servers full_path_to_list_of_properties"
  exit
fi
 
if [ ! -e "$1" ] || [ ! -e "$2" ]
then
  echo "can't find either $1 or $2"
  exit
fi
 
SERVERFILE="$1"
TAGSFILE="$2"
date >&2
echo "using $SERVERFILE for the list of servers" >&2
echo "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" >&2
blcli_connect
if [ $? -ne 0 ]
then
  echo "can't connect blcli"
  exit
fi
echo "connected." >&2
 
echo "validating the list of properties" >&2
validate_tags
 
if [ -z "$VALIDTAGS" ]
then
  echo "no parameter is valid"
  exit
else
  echo "the following properties are valid:"`echo "$VALIDTAGS" | tr '|' ','` | tr -d ^ >&2
fi
 
 
echo "processing list of servers" >&2
echo "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 ""
  fi
done
blcli_disconnect
 
date >&2
echo "done" >&2

 
 
4. 스크립트 실행 및 출력
 
# nsh get_properties_for_servers.nsh 5servers.txt properties > sample_output.csv
Wed Oct 8 05:33:39 EDT 2008
using servers.txt for the list of servers
using properties for the list of properties
connecting
connected.
validating the list of properties
the following properties are valid:ASSET_ID,ENVIRONMENT,MAINTENANCE_WINDOW,PATCH_GROUP
processing list of servers
Wed Oct 8 05:33:47 EDT 2008
done
 
suprhas30serv1# cat sample_output.csv
server,ASSET_ID,ENVIRONMENT,MAINTENANCE_WINDOW,PATCH_GROUP
server1, AST0047093, Test Lab, Sunday 12:00 a.m. - 4:00 a.m., EUT - TEST
server2, AST0047107, Test Lab, Sunday 12:00 a.m. - 4:00 a.m., EUT - TEST
server3, AST0047120, Test Lab, Sunday 12:00 a.m. - 4:00 a.m., EUT - TEST
server4, AST0047177, Test Lab, Sunday 12:00 a.m. - 4:00 a.m., EUT - TEST
server5, AST0047122, Test Lab, Sunday 12:00 a.m. - 4:00 a.m., EUT - TEST

좋은 웹페이지 즐겨찾기