<div dir="ltr">This option was added with util-linux v2.25 in 2014. If you're using an older version or the Busybox `logger` instead, well, it won't have that.<div><br></div><div>The alternative is to write your own C tool that uses libsystemd and calls <a href="https://manpages.debian.org/testing/libsystemd-dev/sd_journal_send.3.en.html">sd_journal_send</a>() with the correct fields (libsystemd is definitely going to be present), or a Python tool that uses systemd.journal.send(). (Or maybe call libsystemd through python ctypes or whatever other FFI mechanism is available.)</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 22, 2021 at 4:32 PM DHAIY DHAIY <<a href="mailto:dhaiy@msn.com">dhaiy@msn.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Thanks a lot Mantas.</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
But in my sytem, logger does not have "--journal".</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Are you aware of other tools from bash which can be used?</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
BR<br>
</div>
<div id="gmail-m_4190535454060497493appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_4190535454060497493divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>发件人:</b> Mantas Mikulėnas <<a href="mailto:grawity@gmail.com" target="_blank">grawity@gmail.com</a>><br>
<b>发送时间:</b> 2021年10月22日 18:45<br>
<b>收件人:</b> DHAIY DHAIY <<a href="mailto:dhaiy@msn.com" target="_blank">dhaiy@msn.com</a>><br>
<b>抄送:</b> <a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">systemd-devel@lists.freedesktop.org</a> <<a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">systemd-devel@lists.freedesktop.org</a>><br>
<b>主题:</b> Re: [systemd-devel] 回复: Is it possible to send a string to the journal of one specific systemd unit</font>
<div> </div>
</div>
<div>
<div dir="ltr">If you have root privileges (i.e. UID 0), then yes, you can send a journal message with the "OBJECT_SYSTEMD_UNIT=myservice.service" field and journalctl will automatically look for that.
<div><br>
</div>
<div>In C, specify the field when calling sd_journal_sendv(); in bash you can use `logger --journal`:</div>
<div><br>
</div>
<div><font face="monospace">(echo "OBJECT_SYSTEMD_UNIT=sshd.service";<br>
 echo "MESSAGE=Hello world!") | sudo logger --journal</font><br>
</div>
</div>
<br>
<div>
<div dir="ltr">On Fri, Oct 22, 2021 at 11:43 AM DHAIY DHAIY <<a href="mailto:dhaiy@msn.com" target="_blank">dhaiy@msn.com</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<div>
<p>Saying we have a systemd unit named "myservice". <br>
</p>
<p>we can use <strong>journalctl -u myservice</strong> to inspect the logs generated by myservice.</p>
<p><br>
</p>
<p>But is there a way to insert one string from command-line into myservice's journal so that it can be seen by
<strong>journalctl -u myservice</strong> later?</p>
</div>
<br>
</div>
<div id="gmail-m_4190535454060497493x_gmail-m_-3445245133184752786appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_4190535454060497493x_gmail-m_-3445245133184752786divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>发件人:</b> DHAIY DHAIY<br>
<b>发送时间:</b> 2021年10月22日 16:40<br>
<b>收件人:</b> <a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">
systemd-devel@lists.freedesktop.org</a> <<a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">systemd-devel@lists.freedesktop.org</a>><br>
<b>主题:</b> Is it possible to send a string to the journal of one specific systemd unit</font>
<div> </div>
</div>
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<div>
<p>Saying we have a systemd unit named "myservice". <br>
</p>
<p>we can use <strong>journalctl -u myservice</strong> to inspect the logs generated by myservice.</p>
<p><br>
</p>
<p>But is there a way to insert one string from command-line into myservice's journal so that it can be seen by
<strong>journalctl -u myservice</strong> later?</p>
</div>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">
<div dir="ltr">Mantas Mikulėnas</div>
</div>
</div>
</div>

</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div>