출처: http://web-dev.tistory.com/117
cut 이랑 uniq 사용법
예) 현재 접속된 ip만 확인(포트번호 제외)하여 중복된 것을 제거한 갯수
# netstat -an | grep ESTABLISHED | awk '{print ($2)}' |cut -f "1 2 3 4" -d .| sort | uniq -c
- date 관련
1. date 0없애기
# date '+%h %-d'
Aug 04
# date '+%h %0d'
Aug 4
2. date 전달 구하기
# TZ=KST+700 date +'%m'
3. data 전일 구하기
# TZ=KST+15 date +'%d'
- du 관련
1. 현재 디렉토리 내의 모든 파일의 용량을 보여줌
# du -sk * (du -sm * 및 du -sg * 가능)
2. 같은 파일시스템 내의 디렉토리 사이즈만 보여줌
# du -x
- awk 사용예제
# df -m | awk '{print$7}'
# df -m | awk '{print$1,$7}'
# lsvg -l rootvg | awk '{print"lslv -l "$1}' | sh
# df | awk '{print"lsfs "$7}'|sh
# lsdev -Cc adapter | grep ent | awk '{print"lsattr -El "$1}' | sh
# ps -ef | grep nmon |awk '{print"kill -9 "$2}' |sh
# ls -l /etc/*.conf| awk '{print "grep pmtu " $9}' | sh
(디렉토리의 사용량 보기)
# ls -l|grep ^d | awk '{print"du -sk "$9}' | sh
(파일시스템 90% 이상 찾기)
# df -Pk|awk 'int($2) != 0'|grep -v Mounted|grep -v 가능|awk 'int($3*100/$2) > 89 {print $5, $6}'
(메모리 사용량 보기)
# vmstat 1 3 |tail -1 |awk '{used=$3*4096/1024/1024}{free=$4*4096/1024/1024}END{printf " used memory : %.0f MB\n free memory : %.0f MB\n",used,free}'
(CPU사용량보기)
# sar 1 2|tail -1|awk '{use=int($2+$3)}END{printf "%.0f\n",use}'
(HP에서 disk용량 보기)
# ioscan -fnC disk|grep rdsk|awk '{print "diskinfo "$2}'|sh|grep size|grep -v '0 Kbytes'|awk '{print int($2/1024/1024)}'
- 일일점검 shell(AIX 기준)
export LANG=C
DATE=`date '+%y%m%d'`
MONTH=`date '+%y%m'`
TIME=`date '+%H%M%S'`
HOST=`hostname`
SCRIPT_HOME=/CHECK
TEMP_HOME=$SCRIPT_HOME/TEMP
LOG_HOME=$SCRIPT_HOME/LOG
OUTPUT=$LOG_HOME/systemcheck_$HOST'_'$DATE.out
NET_INFO=$SCRIPT_HOME/TEMP/ifconfig.info
NET_TEMP=$SCRIPT_HOME/TEMP/ifconfig.count
####### MEMORY CHECK ########
MEMINUSE=`svmon -G | grep "in use" | awk '{print ($3)}'`
MEMTOTAL=`svmon -G | grep "memory" | awk '{print ($3/$2)*100}'`
MEMCOMP=`svmon -G | grep "memory" | awk '{print ('$MEMINUSE'/$2*100)}'`
MEMNONCOMP=`echo "scale=3; $MEMTOTAL - $MEMCOMP"|bc`
####### NETWORK CHECK ########
> $NET_INFO < /dev/null
> $NET_TEMP < /dev/null
ifconfig -a | grep en | grep -v tcp | awk '{print $1}' | cut -c 1-3 > $NET_INFO
for NET_EN in $(<$NET_INFO)
do
netstat -v $NET_EN | grep Link | grep -iv Up | wc -l >> $NET_TEMP
done
echo "CPU = `sar 1 2|tail -1|awk '{use=int($2+$3)}END{printf "%.0f\n",use}'`" > $OUTPUT
echo "MEM/COMP = $MEMCOMP" >> $OUTPUT
echo "MEM/NONCOMP = $MEMNONCOMP" >> $OUTPUT
echo "MEM/SWAP = `lsps -a | grep hd6 | awk '{ print $5 }'`" >> $OUTPUT
echo "DISK = `df -Pk|awk 'int($2) != 0'|awk 'int($3*100/$2) > 95 {print $5, $6}' | wc -l`" >> $OUTPUT
echo "NETWORK = `cat $NET_TEMP | grep -v 0 | wc -l`" >> $OUTPUT
CHECK=`lssrc -a | grep topsvcs | grep active | wc -l`
if [ $CHECK = 1 ] ; then
echo "CLUSTER/DEMON = 0" >> $OUTPUT
echo "CLUSTER/LOG = `cat /tmp/hacmp.out | wc -l`" >> $OUTPUT
else
echo "CLUSTER/DEMON = 1" >> $OUTPUT
fi
echo "ERRORLOG = `errpt | grep -v ID | grep -v SOFTWARE | wc -l`" >> $OUTPUT
- 벤더별 메모리 사용량 체크
[IBM]
export LANG=C
SCRIPT_HOME=/수정하세요
####### MEMORY CHECK ########
MEMINUSE=`svmon -G | grep "in use" | awk '{print ($3)}'`
MEMTOTAL=`svmon -G | grep "memory" | awk '{print ($3/$2)*100}'`
MEMCOMP=`svmon -G | grep "memory" | awk '{print ('$MEMINUSE'/$2*100)}'`
MEMNONCOMP=`echo "scale=3; $MEMTOTAL - $MEMCOMP"|bc`
echo "CPU = `sar 1 2|tail -1|awk '{use=int($2+$3)}END{printf "%.0f\n",use}'`"
echo "MEM/COMP = $MEMCOMP"
echo "MEM/NONCOMP = $MEMNONCOMP"
echo "SWAP = `lsps -a | grep hd6 | awk '{ print $5 }'`"
[HP]
export LANG=C
SCRIPT_HOME=/수정하세요
####### MEMORY CHECK ########
MEMFREE=`vmstat 1 2 | tail -1 | awk '{ printf "%-d\n", $5*4}'`
MEMTOTAL=`echo "phys_mem_pages/D" | adb /stand/vmunix /dev/kmem|tail -1|awk '{ printf "%-d\n", $2*4}'`
MEMUSE=`echo "scale=3; 100-($MEMFREE*100/$MEMTOTAL)"|bc`
echo "CPU = `sar 1 2|tail -1|awk '{use=int($2+$3)}END{printf "%.0f\n",use}'`"
echo "MEM = $MEMUSE"
echo "SWAP = `/usr/sbin/swapinfo -tm|tail -1|awk '{use=int($3*100/$2)}END{printf "%.0f\n",use}'`"
[SUN]
export LANG=C
SCRIPT_HOME=/수정하세요
####### MEMORY CHECK ########
MEMTOTAL=`prtconf|grep Mem|awk '{print $3}'`
MEMFREE=`sar -r 1 2|tail -1|awk '{use=int($2*8/1024)}END{printf "%.0f\n",use}'`
MEMUSE=`echo "scale=3; 100-($MEMFREE*100/$MEMTOTAL)"|bc`
echo "CPU = `sar 1 2|tail -1|awk '{use=int($2+$3)}END{printf "%s\n",use}'`"
echo "MEM = $MEMUSE"
echo "SWAP = `swap -l|tail -1|awk '{use=int(100-($5*100/$4))}END{printf "%s\n",use}'`"
- system 정보 저장하는 shell
#!/bin/sh
IdChk=`id | grep root | wc -l`
if [ $IdChk -eq 0 ]; then
echo
echo "You must login root... Try again..."
echo
exit
fi
OutFile=`hostname`"_"`date +%y%m%d`.out"
echo "-------------------------------------------"| tee -a $OutFile
echo " 시스템 정기 점검 "| tee -a $OutFile
echo "-------------------------------------------"| tee -a $OutFile
echo '1. 점검 일자 : ' `date` | tee -a $OutFile
echo '2. 장비 이름 : ' `hostname` | tee -a $OutFile
echo '3. 모 델 명 : ' `uname -M` | tee -a $OutFile
echo '4. 시리얼번호 : ' `uname -u` | tee -a $OutFile
echo '5. OS 버젼 : ' `oslevel -r` | tee -a $OutFile
echo '6. 커널 비트 : ' `bootinfo -K` | tee -a $OutFile
echo | tee -a $OutFile
echo | tee -a $OutFile
echo " =====================" | tee -a $OutFile
echo " CPU / MEMORY 정보확인" | tee -a $OutFile
echo " =====================" | tee -a $OutFile
echo | tee -a $OutFile
echo "# lsdev -Cc processor" | tee -a $OutFile
lsdev -Cc processor | tee -a $OutFile
echo | tee -a $OutFile
echo "# bootinfo -r" | tee -a $OutFile
bootinfo -r | tee -a $OutFile
echo | tee -a $OutFile
echo "# lscfg -vp |grep Size" | tee -a $OutFile
lscfg -vp |grep Size | tee -a $OutFile
echo | tee -a $OutFile
echo "# lsps -a" | tee -a $OutFile
lsps -a | tee -a $OutFile
echo | tee -a $OutFile
echo | tee -a $OutFile
echo " ==============" | tee -a $OutFile
echo " DISKS 정보확인" | tee -a $OutFile
echo " ==============" | tee -a $OutFile
echo | tee -a $OutFile
lscfg -vp | grep disk | tee -a $OutFile
echo | tee -a $OutFile
echo " =================" | tee -a $OutFile
echo " ADAPTERS 정보확인" | tee -a $OutFile
echo " =================" | tee -a $OutFile
echo | tee -a $OutFile
echo "# lsdev -Cc adapter" | tee -a $OutFile
lsdev -Cc adapter | tee -a $OutFile
echo | tee -a $OutFile
echo " =================" | tee -a $OutFile
echo " SLOT 정보확인" | tee -a $OutFile
echo " =================" | tee -a $OutFile
echo | tee -a $OutFile
echo "# lsslot -c pci" | tee -a $OutFile
lsslot -c pci | tee -a $OutFile
echo | tee -a $OutFile
echo " ===================" | tee -a $OutFile
echo " CDROM 장치 정보확인" | tee -a $OutFile
echo " ===================" | tee -a $OutFile
echo | tee -a $OutFile
echo "# lsdev -Cc cdrom" | tee -a $OutFile
lsdev -Cc cdrom | tee -a $OutFile
echo " ===================" | tee -a $OutFile
echo " TAPE 장치 정보확인" | tee -a $OutFile
echo " ===================" | tee -a $OutFile
echo | tee -a $OutFile
echo "# lsdev -Cc tape" | tee -a $OutFile
lsdev -Cc tape | tee -a $OutFile
echo | tee -a $OutFile
echo " ===================" | tee -a $OutFile
echo " File Systems 사용량" | tee -a $OutFile
echo " ===================" | tee -a $OutFile
echo | tee -a $OutFile
echo "# df -Pk" | tee -a $OutFile
df -Pk | tee -a $OutFile
echo | tee -a $OutFile
echo " ============" | tee -a $OutFile
echo " LVM 정보확인" | tee -a $OutFile
echo " ============" | tee -a $OutFile
echo | tee -a $OutFile
echo "# lsvg " | tee -a $OutFile
lsvg| tee -a $OutFile
echo | tee -a $OutFile
echo "# lsvg -o" | tee -a $OutFile
lsvg -o| tee -a $OutFile
echo | tee -a $OutFile
echo "# lspv " | tee -a $OutFile
lspv| tee -a $OutFile
echo | tee -a $OutFile
echo "# lsvg |awk '{print "lsvg -l "$1}'|sh" | tee -a $OutFile
lsvg |awk '{print "lsvg -l "$1}'|sh | tee -a $OutFile
echo | tee -a $OutFile
echo " ================" | tee -a $OutFile
echo " NETWORK 정보확인" | tee -a $OutFile
echo " ================" | tee -a $OutFile
echo | tee -a $OutFile
echo "# ifconfig -a " | tee -a $OutFile
ifconfig -a| tee -a $OutFile
echo | tee -a $OutFile
echo "# netstat -rn " | tee -a $OutFile
netstat -rn| tee -a $OutFile
echo | tee -a $OutFile
echo "# EtherChannel " | tee -a $OutFile
for ENT in `lsdev -Cc adapter|grep EtherChannel|awk '{print $1}'`
do
echo ""
echo "== $ENT =="
lsattr -El $ENT | tee -a $OutFile
done
echo "# Duplex" | tee -a $OutFile
for ENT in `lsdev -Cc adapter|grep ent|grep -v EtherChannel|awk '{print $1}'`
do
echo ""
echo "== $ENT =="
lsattr -El $ENT | grep speed | tee -a $OutFile
done
echo " ====================" | tee -a $OutFile
echo " ENVIRONMENT 정보확인" | tee -a $OutFile
echo " ====================" | tee -a $OutFile
echo | tee -a $OutFile
echo "# crontab -l " | tee -a $OutFile
crontab -l| tee -a $OutFile
echo | tee -a $OutFile
echo "# cat /etc/passwd " | tee -a $OutFile
cat /etc/passwd| tee -a $OutFile
echo | tee -a $OutFile
echo "# cat /etc/group " | tee -a $OutFile
cat /etc/group| tee -a $OutFile
echo | tee -a $OutFile
echo "# cat /.profile " | tee -a $OutFile
cat /.profile| tee -a $OutFile
echo | tee -a $OutFile
echo "# cat /etc/filesystems " | tee -a $OutFile
cat /etc/filesystems| tee -a $OutFile
echo | tee -a $OutFile
echo "# cat /etc/environment " | tee -a $OutFile
cat /etc/environment| tee -a $OutFile
echo | tee -a $OutFile
echo "# ulimit -a " | tee -a $OutFile
ulimit -a| tee -a $OutFile
echo | tee -a $OutFile
echo "# lsattr -El sys0 " | tee -a $OutFile
lsattr -El sys0| tee -a $OutFile
echo | tee -a $OutFile
echo "# lsattr -El aio0 " | tee -a $OutFile
lsattr -El aio0 | tee -a $OutFile
echo | tee -a $OutFile
echo "# vmo -a|egrep 'perm|repage' " | tee -a $OutFile
vmo -a|egrep "perm|repage" | tee -a $OutFile
echo | tee -a $OutFile
echo " ==============" | tee -a $OutFile
echo " Error Log 확인" | tee -a $OutFile
echo
" ==============" | tee -a $OutFile
echo | tee -a $OutFile
echo "# errpt" | tee -a $OutFile
errpt | tee -a $OutFile
echo | tee -a $OutFile
echo " ========" | tee -a $OutFile
echo " LPP 확인" | tee -a $OutFile
echo " ========" | tee -a $OutFile
echo | tee -a $OutFile
echo "# lppchk -v" | tee -a $OutFile
lppchk -v | tee -a $OutFile
echo | tee -a $OutFile
echo "# lslpp -l" | tee -a $OutFile
lslpp -l | tee -a $OutFile
echo | tee -a $OutFile
echo " ========" | tee -a $OutFile
echo " ETC 확인" | tee -a $OutFile
echo " ========" | tee -a $OutFile
echo | tee -a $OutFile
echo "# lsconf" | tee -a $OutFile
lsconf | tee -a $OutFile
echo | tee -a $OutFile
echo "# lscfg -vp " | tee -a $OutFile
lscfg -vp | tee -a $OutFile
echo | tee -a $OutFile
echo "# ps -ef " | tee -a $OutFile
ps -ef | tee -a $OutFile
echo | tee -a $OutFile
echo "# bootlist -m normal -o " | tee -a $OutFile
bootlist -m normal -o | tee -a $OutFile
echo | tee -a $OutFile
echo 'Ending Date : ' `date` | tee -a $OutFile
- 사용자 자동 생성 shell
* 인자값 입력형(예: user.sh 아이디 비번)
OID=`cat /etc/passwd|tail -1|cut -f 3 -d :`
NID=`echo "scale=0; $OID + 1"|bc`
UID=$1
x() {
LIST=
SET_A=
for i in "$@"
do
if [ "$i" = "admin=true" ]
then
SET_A="-a"
continue
fi
LIST="$LIST \"$i\""
done
eval mkuser $SET_A $LIST
}
x id='$NID' home='/u/$UID' rlogin='false' $UID
PW=$2
echo "$UID:$PW"|chpasswd
pwdadm -c $UID
echo "$UID 생성 완료"
* 대화형(예:user.sh)
OID=`cat /etc/passwd|tail -1|cut -f 3 -d :`
NID=`echo "scale=0; $OID + 1"|bc`
read UID?'사번을 입력하세요 => '
x() {
LIST=
SET_A=
for i in "$@"
do
if [ "$i" = "admin=true" ]
then
SET_A="-a"
continue
fi
LIST="$LIST \"$i\""
done
eval mkuser $SET_A $LIST
}
x id='$NID' home='/u/$UID' rlogin='false' $UID
read PW?'비밀번호를 입력하세요 => '
echo "$UID:$PW"|chpasswd
pwdadm -c $UID
echo "$UID 생성 완료"
- DD 사용(원격)
블럭 디바이스
# dd if=/dev/hd3| rsh localhost "dd of=/dev/lv00 bs=1920000"
캐릭터 디바이스
# dd if=/dev/rlv01 ibs=64k obs=512 | rsh hostname dd ibs=512 obs=64k of=/dev/rlv01
- tar 사용
1. Compress(압축)명령
. tar(create tape archives, and add or extract files)
:파일들을 묶어주는 명령들이다.(압축하지는 않습니다.)
ex) tar -cvf [만들 filename.tar] * ==> 묶을 때 보통 tar이라는 확장자를 씁니 다.
그러면 filename.tar이라는 파일이 생성 됩니다.
tar -xvf [풀 filename] ==> 묶였던 파일들이 다시 풀립니다.
compress, uncompress
: 파일을 압축하는 명령입니다. compress는 압축 uncompress는 풀어주는 명령입 니다.
ex) compress [filename] ==> filename.Z 가 생성됩니다.
# compress temp.tar ==> temp.tar.Z 가 생성됩니다.
-v 는 압축률을 보여줍니다.
# compress -v temp.tar
compress는 tar처럼 새로운 파일을 만드는 것이 아니고 원본파일을 압축하기만 합니다.
# uncompress [압축한 filename] ==> 원래의 파일이 됩니다.
. gzip, gunzip
: 역시 파일을 압축하고 푸는 명령입니다. 보통 compress보다 성능이 좋습니다. 역시 -v option이 있습니다.
ex) gzip [fileanme] ==> filename.gz 가 생성
# gzip -v temp.tar ==> temp.tar.gz 가 생성됨
gunzip [filename]
# gunzip temp.tar.gz ==> 원본인 temp.tar가 됨
2. tar백업(파이프 이용)
# tar -cvf - .|(cd /logdata_recover/ && tar -xvf -)
# tar -cvf- <path> | rsh <t_mach> "cd <path> && tar -xvf-"
- AIO관련 (aio활성화 후 재부팅 해야 적용되는 줄 알았는데...)
# mkdev -l aio0
이렇게 하거나
# smitty aio -> Configure Defined Asynchronous I/O
- AIX(ksh)에서 파일명 자동완성(리눅스에서 일부만 입력후 tab키 누르는 것과 같은 효과)
[ESC] + [=] 실행가능 list up
[ESC] + [\] 파일명 자동완성
- AIX에서 최대 생성가능 스레드 개수(확인 방법)
기본값은 process당 32767 개
# vi /usr/include/pthread.h 파일을 열어서 PTHREAD_THREADS_MAX 값을 확인 함
- process top10구현
# ps gu |head -n 1; ps gu | egrep -v "CPU|kproc"|sort +2b -3 -n -r | head -n 10
- svmon 상위 15개 용량
# svmon -Pt15|perl -e 'while(<>){print if($.==2||$&&&!$s++);$.=0 if(/^-+$/)}'
- 터미널(secure CRT등) 글자 깨질때(예: 바이너리파일을 열때 cat /usr/bin/ls)
# echo <ctrl+V><Ctrl+O><Enter>
- 미들웨어 버전 확인
# su - jeus -c 'jeusadmin -fullversion'
# su - webtob -c 'wsadmin -v'
# su - anylink -c 'tmadmin -v'
# su - tmax -c 'tmadmin -v'
'::: OS ::: > AIX' 카테고리의 다른 글
nmon 및 애널라이저 (0) | 2009.05.14 |
---|---|
NMON, NMON Analyser를 이용한 시스템 성능 리포트 만들기 (0) | 2009.05.14 |
tar 명령 사용법 정리 (0) | 2009.04.02 |
AIX에서 메모리 점유가 높은 프로세스 찾기 (0) | 2008.12.10 |
AIX 보안 설정 및 체크리스트 (0) | 2008.10.25 |