Log Server
# vi /etc/rsyslog.conf
#$ModLoad imtcp
#$InputTCPServerRun 514
$ModLoad imtcp
$InputTCPServerRun 514
$AllowedSender TCP, 127.0.0.1, 10.3.1.0/24, 10.5.1.0/24
local1.* /var/log/cmd.log
# service rsyslog restart
CLIENT
# vi /etc/profile.d/cmd_logging.sh
function logging
{
stat="$?"
cmd=$(history|tail -1|cut -d ' ' -f 5-)
if [ "$cmd" != "$cmd_old" ]; then
logger -p local1.notice "[NL2,2] STAT=$stat USER=$USER"
logger -p local1.notice "[NL2,1] PID=$$, PWD=$PWD, CMD=$cmd"
fi
cmd_old=$cmd
}
trap logging DEBUG
※ logger : 지정한 메시지를 facility(local1.notice) syslog로 메시지를 보낸다.
※ trap : bash 내부명령어이며 특정 시그널이 발생할 때 지정한 명령어가 실행
// DEBUG 형태 : 명령이 실행될 때 마다 logging function을 호출
# chmod 755 /etc/profile.d/cmd_logging.sh
# vi /etc/rsyslog.conf
local1.* @@10.3.1.201:514
# service rsyslog restart
'Lang_Development > BASH' 카테고리의 다른 글
디렉토리 별 파일 갯수 (0) | 2015.11.05 |
---|---|
[BASH] How to cut the last field from a shell string (0) | 2013.12.09 |
[BASH] /bin/bash^M: bad interpreter: No such file or directory (0) | 2013.08.01 |
[sed] sed에서 shell 명령어 사용 (0) | 2013.04.22 |
숫자, 문자를 순차적으로 출력 (0) | 2012.12.30 |
최근댓글