Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Nov 2017 22:08:37 +0100
From:      Polytropon <freebsd@edvax.de>
To:        Ernie Luzar <luzar722@gmail.com>
Cc:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Re: sh script echo to  syslog
Message-ID:  <20171108220837.c6cb234d.freebsd@edvax.de>
In-Reply-To: <5A036890.7090204@gmail.com>
References:  <5A036890.7090204@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 08 Nov 2017 15:26:56 -0500, Ernie Luzar wrote:
> Hello list;
> 
> I have a sh script that I use echo "message text" and it shows on the 
> terminal console that started the script. Thats ok, but I would like to 
> also have that same message posted the syslog.

The easiest way is to use the "logger" command, for example:

	logger -t <scriptname> "<message text>"

If you omit -t <name>, the user account under which the script
runs will be logged; it's probably easier to use the scripts
own identifier for this purpose. If you don't want it to be
hard-coded, use this:

	logger -t `basename $0` "<message text>"

Or with one external program call less:

	logger -t ${0##*/} "<message text>"

That's probably the most convenient approach. :-)




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20171108220837.c6cb234d.freebsd>