실습> logger 사용하기
logger : 로그를 기록하는 명령어
주로 쉘스크립트에서 로그를 기록할 때 사용한다.
# logger --help
Usage:
logger [options] [message]
Options:
-T, --tcp use TCP only
-d, --udp use UDP only
-i, --id log the process ID too
-f, --file <file> log the contents of this file
-h, --help display this help text and exit
-S, --size <num> maximum size for a single message (default 1024)
-n, --server <name> write to this remote syslog server
-P, --port <port> use this port for UDP or TCP connection
-p, --priority <prio> mark given message with this priority
-s, --stderr output message to standard error as well
-t, --tag <tag> mark every line with this tag
-u, --socket <socket> write to this Unix socket
-V, --version output version information and exit
# logger "ALERT exited abnormally with [1]"
# hostname
web1.linuxmaster.net
# echo $USER
root
# tail -1 /var/log/messages
Mar 4 21:39:36 web1 root: ALERT exited abnormally with [1]
# date
2022. 03. 04. (금) 21:40:36 KST
logger -t 옵션을 이용해서 로그를 기록하는 tag를 수정한다.
# akdfjadf 2> /dev/null
# EXITVALUE=$?
# logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
# echo $EXITVALUE
127
# tail -1 /var/log/messages
Mar 4 21:42:58 web1 logrotate: ALERT exited abnormally with [127]
'Linux > 보안장비 운용' 카테고리의 다른 글
| 아파치 인증 설정하기 (0) | 2022.03.08 |
|---|---|
| 웹서버 로그 분석 툴 goaccess 설치하기 (0) | 2022.03.08 |
| logrotate 실행하기 (0) | 2022.03.04 |
| 로그 관리 프로그램 logrotate (0) | 2022.03.04 |
| 원격 로그 서버 구축하기 (0) | 2022.03.04 |