sh script echo to syslog

Polytropon freebsd at edvax.de
Wed Nov 8 21:08:43 UTC 2017


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, ...


More information about the freebsd-questions mailing list