commit 2d522c1f02a353f43cf160fea4a1861f47cc4e7b Author: caes Date: Thu May 21 08:22:23 2020 -0400 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..7ea136f --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +This is a simple script providing a BASH interface to log to a remote syslog server. diff --git a/syslog.sh b/syslog.sh new file mode 100644 index 0000000..dece692 --- /dev/null +++ b/syslog.sh @@ -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