mirror of
https://asciireactor.com/otho/bash-logger.git
synced 2024-11-21 13:05:06 +00:00
init
This commit is contained in:
commit
2d522c1f02
1
README.md
Normal file
1
README.md
Normal file
@ -0,0 +1 @@
|
||||
This is a simple script providing a BASH interface to log to a remote syslog server.
|
44
syslog.sh
Normal file
44
syslog.sh
Normal file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Set syslog_local="TRUE" to only log locally.
|
||||
|
||||
syslog_host="syslog.adamonet"
|
||||
syslog_port="514"
|
||||
syslog_type="tcp"
|
||||
syslog_facility="local7"
|
||||
|
||||
if [[ -z ${syslog_facility} ]]; then
|
||||
syslog_facility="local7";
|
||||
fi
|
||||
message="${*:2}"
|
||||
if [[ -z $2 ]]; then
|
||||
priority="${syslog_facility}.info"
|
||||
message="$1"
|
||||
else
|
||||
case $1 in
|
||||
0|e*) priority="${syslog_facility}.emerg" ;;
|
||||
1|a*) priority="${syslog_facility}.alert" ;;
|
||||
2|c*) priority="${syslog_facility}.crit" ;;
|
||||
3|e*) priority="${syslog_facility}.err" ;;
|
||||
4|w*) priority="${syslog_facility}.warning" ;;
|
||||
5|n*) priority="${syslog_facility}.notice" ;;
|
||||
6|i*) priority="${syslog_facility}.info" ;;
|
||||
7|d*) priority="${syslog_facility}.debug" ;;
|
||||
*)
|
||||
echo "Exit: invalid severity level. No log sent."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [[ $syslog_local == "TRUE" ]]; then
|
||||
logger -i \
|
||||
-p "${priority}" \
|
||||
"${message}"
|
||||
else
|
||||
logger -i --tcp \
|
||||
-n $syslog_host \
|
||||
-P $syslog_port \
|
||||
-p "${priority}" \
|
||||
"${message}"
|
||||
fi
|
Loading…
Reference in New Issue
Block a user