スクリプトはシステムログに書き込めません。

スクリプトはシステムログに書き込めません。

簡単に言えば、私はsystemd台本を通して日記に手紙を書きたいと思います。

これはうまくいきません:

printf "%s\n%s\n%s\n" CODE_FILE=/etc/zsh/zprofile CODE_LINE=31 MESSAGE="could not read /etc/dircolors" | logger --journald

正確なコード(または印刷などの他のバリエーション)を実行すると、ログに何も起こりません。

私はjournalctlそれをそう呼ぶ:

journalctl --full --all --no-pager -n 10

ここに問題がありますか?

ベストアンサー1

使用systemd-cat。パイプまたはプログラムの出力をログに関連付けます。

例:

printf "Write text to the journal" | systemd-cat

結果:

journalctl -xn
[..]
Apr 12 13:37:00 servername [31509]: Write text to the journal

ロギングツールを識別するために追加できます。-ティーオプション:

printf "Write text to the journal" | systemd-cat -t yourIdentifier
journalctl -xn
Apr 12 13:37:00 servername yourIdentifier[31833]: Write text to the journal

編集:指定されたsyslog識別子を持つメッセージのみを表示するには、-tオプションを使用します。

journalctl -t yourIdentifier

このパラメーターは複数回指定できます。

おすすめ記事