
간단히 말해서, 나는 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
이 매개변수는 여러 번 지정할 수 있습니다.
답변2
| systemd-cat
다음과 같은 경우에는 작동하지 않습니다.
- 스크립트는 systemd에 의해 직접 실행되며
- 스크립트가 stdout/stderr(
exec 1>>$LOGFILE
) 을 리디렉션했습니다.
이렇게 해도 이것은 여전히 사실입니다 | tee systemd-cat
.
이 경우 가장 좋은 방법은 이를 반대로 하는 것입니다.
- 표준 출력 리디렉션 제거
- 휴대
printf
전화로 해보세요| tee -a $LOGFILE