Drew Noakes Asked: 2014-10-31 03:15:09 +0800 CST2014-10-31 03:15:09 +0800 CST 2014-10-31 03:15:09 +0800 CST Write to syslog from the command line 772 How can I write an entry into /var/log/syslog from the command line? command-line 3 Answers Voted Drew Noakes 2014-10-31T03:15:09+08:002014-10-31T03:15:09+08:00 Use the logger command. logger Some message to write There are several options available, including: -i Log the process ID in each line -f Log the contents of a specified file -n Write to the specified remote syslog server -p Specify a priority -t Tag the line with a specified tag See man 1 logger for more information on the tool. Sylvain Pineau 2014-10-31T03:34:29+08:002014-10-31T03:34:29+08:00 Alternatively, you can write to syslog from python: python -c 'import syslog; syslog.syslog("Hello World")' DarkNeuron 2020-05-08T00:31:49+08:002020-05-08T00:31:49+08:00 As a dev, I rarely have time to closely study man pages, so TLDR: logger -p local0.notice -t ${0##*/}[$$] Hello world The gibberish in the middle will translate to the calling program. So if you check the bottom of syslog you'll see something like: May 07 08:27:14 ip-10-1-11-166 -bash[42108]: Hello world
Use the
logger
command.There are several options available, including:
See
man 1 logger
for more information on the tool.Alternatively, you can write to
syslog
from python:As a dev, I rarely have time to closely study
man
pages, so TLDR:The gibberish in the middle will translate to the calling program. So if you check the bottom of syslog you'll see something like: