리눅스, 자료실, 성경검색, 추억의게임, 고전게임, 오락실게임, rootman, http://www.rootman.co.kr
* 54.224.118.247 *
| Home | Profile | Linux | 자료실 | zabbix | Mysql 5.6 | 갤러리 | 성경검색 | 해피니스 | 자유게시판 | 게시물검색 | L | O | R |    

 
[Shell] [최종수정 : 2005/09/12] 서버 상태 값 주기적으로 메일로 발송하기
 작성자 : 루트맨
Date : 2005-01-27 16:36  |  Hit : 10,109  
#!/bin/sh
# 작성일 : 2005/01/27
# http://www.rootman.co.kr
# 제목 : 서버 서비스 상태 표시기
# 별도 수정 사항 : 없음.
# --------------------------------------------------
# 소스 라이브러리 함수 참조
source /etc/sysconfig/network
source /etc/sysconfig/network-scripts/ifcfg-eth0

TMP_log_dir=/var/log; # 임시 디렉터리
Web_user="nobody"; # httpd.conf에 선언된 유저 정보
Exclude_File="cache_|sess_"; # /tmp 디렉터리의 정상적인 파일 정보 "|"로 구분


Email=[email protected];

# 네트워크 활성화 체킹
if [ ${NETWORKING} = "no" ]
then
exit 0
fi

#
eval 'ls -asl /tmp/* |grep ${Web_user}|grep -v -E "${Exclude_File}" > ${TMP_log_dir}/tmplog.txt';
for i in $(cat ${TMP_log_dir}/tmplog.txt |awk -F" " '{print $10}')
do
chmod 000 $i;
done;


# 문법
(
echo "---------------------------------------------------------------------------" && \\
echo "1. uptime 값" && \\
echo "---------------------------------------------------------------------------" && \\
uptime && echo -e "\\n" && \\
echo "---------------------------------------------------------------------------" && \\
echo "2. w 값" && \\
echo "---------------------------------------------------------------------------" && \\
w && echo -e "\\n" && \\
echo "---------------------------------------------------------------------------" && \\
echo "3. 메모리 값" && \\
echo "---------------------------------------------------------------------------" && \\
free -m && echo -e "\\n" && \\
echo "---------------------------------------------------------------------------" && \\
echo "4. netstat -ln 값" && \\
echo "---------------------------------------------------------------------------" && \\
netstat -ln && echo -e "\\n" && \\
echo "---------------------------------------------------------------------------" && \\
echo "5. /tmp 리스트값" && \\
echo "---------------------------------------------------------------------------" && \\
ls -asl /tmp/*|grep -v -E "sess_*|mysql.sock" && echo -e "\\n" && \\
echo "---------------------------------------------------------------------------" && \\
echo "6. 열려진 포트 값 조회" && \\
echo "---------------------------------------------------------------------------" && \\
nmap -p 1-1024 localhost|grep -i "open" && echo -e "\\n" && \\
echo "---------------------------------------------------------------------------" && \\
echo "7. 하드 디스크 사용량 조회" && \\
echo "---------------------------------------------------------------------------" && \\
df -h && echo -e "\\n" && \\
echo "---------------------------------------------------------------------------" && \\
echo "8. pstree 값" && \\
echo "---------------------------------------------------------------------------" && \\
pstree && echo -e "\\n" ) \\
| mail -s "[${IPADDR}] 서비스 상태 표시기" ${Email}

echo "done +";
exit 0;

******************************************************************
---------------------------------------------------------------------------
1. uptime 값
---------------------------------------------------------------------------
2:45pm up 33 days, 18:09, 1 user, load average: 0.32, 0.21, 0.20


---------------------------------------------------------------------------
2. w 값
---------------------------------------------------------------------------
2:45pm up 33 days, 18:09, 1 user, load average: 0.32, 0.21, 0.20
USER TTY FROM [email protected] IDLE JCPU PCPU WHAT
root pts/1 220.75.210.252 1:08pm 0.00s 0.30s 0.01s sh mm.sh


---------------------------------------------------------------------------
3. 메모리 값
---------------------------------------------------------------------------
total used free shared buffers cached
Mem: 502 494 8 0 22 152
-/+ buffers/cache: 319 183
Swap: 2047 0 2047


---------------------------------------------------------------------------
4. netstat -ln 값
---------------------------------------------------------------------------
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 218.38.29.35:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN
udp 0 0 0.0.0.0:35854 0.0.0.0:*
udp 0 0 218.38.29.35:53 0.0.0.0:*
udp 0 0 127.0.0.1:53 0.0.0.0:*
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 1172 /tmp/clamd
unix 2 [ ACC ] STREAM LISTENING 193409351 /tmp/mysql.sock


---------------------------------------------------------------------------
5. /tmp 리스트값
---------------------------------------------------------------------------
24 -rw-r--r-- 1 nobody nobody 22053 Sep 9 14:18 /tmp/cache_c21f969b5f03d33d43e04f8f136e7682_1a171bc9c0d21ece34b62977b78c8a9d
24 -rw-r--r-- 1 nobody nobody 22053 Sep 12 04:36 /tmp/cache_c21f969b5f03d33d43e04f8f136e7682_41a104d246e9850a1b7dd88e27473eca
4 -rw-r--r-- 1 nobody nobody 92 Sep 9 14:26 /tmp/cache_c21f969b5f03d33d43e04f8f136e7682_55823fa7a590b8ae5bb38f6ee457032d
24 -rw-r--r-- 1 nobody nobody 22053 Sep 12 09:56 /tmp/cache_c21f969b5f03d33d43e04f8f136e7682_d1546d731a9f30cc80127d57142a482b
4 -rw-r--r-- 1 nobody nobody 1449 Sep 12 09:56 /tmp/cache_c21f969b5f03d33d43e04f8f136e7682_f5bd9e3e9ba74e91995d3e0245fe910b
0 srwxrwxrwx 1 root root 0 Aug 9 20:32 /tmp/clamd
20 ---------- 1 nobody nobody 18001 Sep 10 12:29 /tmp/hacked.txt
20 ---------- 1 nobody nobody 17314 Sep 5 08:21 /tmp/hd
20 ---------- 1 nobody nobody 19258 Aug 9 10:23 /tmp/r0nin
0 ---------- 1 nobody nobody 0 Sep 12 13:58 /tmp/test

/tmp/pear:
total 44
4 drwxr-xr-x 3 root root 4096 Sep 9 11:41 .
36 drwxrwxrwt 3 root root 36864 Sep 12 14:45 ..
4 drwxr-xr-x 2 root root 4096 Sep 9 19:38 cache


---------------------------------------------------------------------------
6. 열려진 포트 값 조회
---------------------------------------------------------------------------
21/tcp open ftp
22/tcp open ssh
25/tcp open smtp
53/tcp open domain
80/tcp open http
110/tcp open pop-3
953/tcp open rndc


---------------------------------------------------------------------------
7. 하드 디스크 사용량 조회
---------------------------------------------------------------------------
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 4.6G 3.4G 1.0G 77% /
/dev/sda1 144M 17M 120M 12% /boot
/dev/sda5 24G 52M 22G 1% /home
none 251M 0 251M 0% /dev/shm
/dev/sda3 2.9G 663M 2.0G 24% /usr/local
/dev/tmpmount 769M 17M 713M 3% /tmp
/dev/sdb1 15G 7.9G 6.7G 54% /home2
/dev/sdb2 18G 33M 17G 1% /home3


---------------------------------------------------------------------------
8. pstree 값
---------------------------------------------------------------------------
init-+-ahc_dv_0
|-ahc_dv_1
|-bdflush
|-clamd
|-crond
|-ipop3d
|-keventd
|-khubd
|-7*[kjournald]
|-klogd
|-ksoftirqd_CPU0
|-kswapd
|-kupdated
|-libhttpd.ep---67*[libhttpd.ep]
|-loop0
|-6*[mingetty]
|-named---named---3*[named]
|-proftpd
|-read-data-wrapp
|-5*[read-data.pl]
|-rrdtimer
|-safe_mysqld---mysqld---mysqld---mysqld
|-scsi_eh_0
|-scsi_eh_1
|-sendmail
|-sshd---sshd---bash---sh-+-mail
| `-sh---pstree
|-syslogd
`-xinetd


 
 

Total. 645
번호 분류 제목 작성자 등록일 조회수
645 기초강좌 NFS server unable to open connection to tcp6/udp6 networks rootman 09-27 2212
644 php [php] mssql ms-sql 한글 변환 끄적임.. 정리 rootman 03-29 3244
643 기초강좌 java vim 에서 자바 환경 만들기 rootman 02-16 2436
642 삭제예정 [xencenter] xenserver tool 설치 rootman 08-24 3405
641 mysql [mysql] Creating a File-Per-Table Tablespace Outside the Dat… rootman 08-03 3587
640 기초강좌 Centos Xwindow 설치 rootman 06-16 4449
639 php [php] highlight 함수 rootman 04-01 4309
638 qmail [qmail] qmail-scanner에 filtering 된 이메일 처리 rootman 02-14 4754
637 Shell [날짜] awk를 이용하여 unixtime의 시간 차 구하기 rootman 01-27 5626
636 기초강좌 centos에 그놈(gnome) 설치하기 rootman 01-10 5549
635 쉘(awk) [awk] shell 변수 사용하기 rootman 12-27 5258
634 기초강좌 서버 캐시 메모리 초기화하기 (drop_caches) rootman 12-11 6223
633 windows tips 그리드 제거 배치 스크립트 rootman 11-28 5828
632 기초강좌 패스워드 lockgin control rootman 09-06 4
631 windows tips win7 자동 로그인 설정하기 rootman 08-18 5651
 1  2  3  4  5  6  7  8  9  10    
AND OR