1. 사용법
Usage:
logger [options] [<message>]
Enter messages into the system log.
Options:
-i log the logger command's PID
--id[=<id>] log the given <id>, or otherwise the PID
-f, --file <file> log the contents of this file
-e, --skip-empty do not log empty lines when processing files
--no-act do everything except the write the log
-p, --priority <prio> mark given message with this priority
--octet-count use rfc6587 octet counting
--prio-prefix look for a prefix on every line read from stdin
-s, --stderr output message to standard error as well
-S, --size <size> maximum size for a single message
-t, --tag <tag> mark every line with this tag
-n, --server <name> write to this remote syslog server
-P, --port <port> use this port for UDP or TCP connection
-T, --tcp use TCP only
-d, --udp use UDP only
--rfc3164 use the obsolete BSD syslog protocol
--rfc5424[=<snip>] use the syslog protocol (the default for remote);
<snip> can be notime, or notq, and/or nohost
--sd-id <id> rfc5424 structured data ID
--sd-param <data> rfc5424 structured data name=value
--msgid <msgid> set rfc5424 message id field
-u, --socket <socket> write to this Unix socket
--socket-errors[=<on|off|auto>]
print connection errors when using Unix sockets
--journald[=<file>] write journald entry
-h, --help display this help
-V, --version display version
For more details see logger(1).
2. 사용 예시
#!/bin/bash
HELLO_ROOT=$(echo "[ $( hostname -I )] $(date '+%Y-%m-%d %H:%M:%S') ROOT_LOGIN - $(w | awk '{ print $3 }' | tail -n 1)")
CONNECT_USER=$(w | grep pts | wc -l)
if [ "${CONNECT_USER}" -ge 1 ]
then
logger -p local6.notice -t HELLO_ROOT ${HELLO_ROOT}
fi
3. 적용 확인(/var/log/messsage)
Nov 28 14:17:41 localhost HELLO_ROOT[5436]: [ 10.101.0.10 ] 2019-11-28 14:17:41 ROOT_LOGIN - xxx.xxx.xxx.xxx