Journalctl에서 systemd-timer 스크립트의 에코 메시지를 표시하는 방법은 무엇입니까?

Journalctl에서 systemd-timer 스크립트의 에코 메시지를 표시하는 방법은 무엇입니까?

일부 프로그램을 시작하고(일부 출력 표시) echo피드백을 제공하는 데 사용되는 시스템 타이머를 통해 쉘 스크립트를 실행합니다.

root@srv ~ [127]# cat /etc/systemd/system/borg.timer
[Unit]
Description=runs borg every hour

[Timer]
OnCalendar=hourly
Persistent=true

[Install]
WantedBy=multi-user.target

root@srv ~# cat /etc/systemd/system/borg.service
[Unit]
Description=borg backup

[Service]
Type=simple
ExecStart=/etc/local/borg.sh
root@srv ~# cat /etc/local/borg.sh
#!/bin/bash

echo "→→→ starting borg backup at $(date)"

# it is OK to move repositories
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
(...)
  • 스크립트를 대화형으로 실행하면 echo두 가지 출력(프로그램 및 출력)이 표시됩니다 journalctl.

  • 타이머를 통해 실행하면 프로그램 출력만 표시됩니다.

후자가 비대화식으로 실행된다는 것을 알고 있지만 프로그램 출력에 누군가가 들어오기 때문에 journalctl타이머는 어떻습니까?

이와 같은 피드백 출력을 스크립트에 표시할 수 있는 방법이 있습니까?


systemctl다음은 journalctl스크립트를 전달하고 임시로 시작할 때의 출력을 비교한 것 입니다 sytemctl start borg. 이제 이것이 "2단계" 스크립트( 무대 뒤에서 자체적으로 bash실행됨 )가 필터링된 출력의 이유가 될 수 있는지 궁금합니다(단순한 추측일 뿐입니다).borg.shpython

출력 systemctl:

root@srv ~# systemctl status borg
● borg.service - borg backup
     Loaded: loaded (/etc/systemd/system/borg.service; static)
     Active: active (running) since Mon 2022-08-08 18:31:54 CEST; 1min 22s ago
TriggeredBy: ● borg.timer
   Main PID: 2651152 (borg.sh)
      Tasks: 2 (limit: 28688)
     Memory: 1.1G
        CPU: 54.304s
     CGroup: /system.slice/borg.service
             ├─2651152 /bin/bash /etc/local/borg.sh
             └─2651737 /usr/bin/python /usr/bin/borg compact /backup/borg/srv

Aug 08 18:32:46 srv borg.sh[2651687]: Keeping archive (rule: weekly #4):       231d5f07-3453-46a5-a466-b8760196e120 Sun, 2022-07-03 23:00:11 [ab22320beda4d0f4ac247686ad>
Aug 08 18:32:46 srv borg.sh[2651687]: Keeping archive (rule: monthly #1):      3b280578-586f-4f62-80c1-b296aa8982c2 Thu, 2022-06-30 23:00:10 [067e23be4b7e33ec7b87f32603>
Aug 08 18:32:48 srv borg.sh[2651687]: ------------------------------------------------------------------------------
Aug 08 18:32:48 srv borg.sh[2651687]:                        Original size      Compressed size    Deduplicated size
Aug 08 18:32:48 srv borg.sh[2651687]: Deleted data:               -3.54 GB             -1.61 GB             -1.33 MB
Aug 08 18:32:48 srv borg.sh[2651687]: All archives:                2.23 TB              1.82 TB            104.85 GB
Aug 08 18:32:48 srv borg.sh[2651687]:                        Unique chunks         Total chunks
Aug 08 18:32:48 srv borg.sh[2651687]: Chunk index:                  199025              7333955
Aug 08 18:32:48 srv borg.sh[2651687]: ------------------------------------------------------------------------------
Aug 08 18:32:48 srv borg.sh[2651152]: →→→ compact backup for /backup/borg/srv
Aug 08 18:33:28 srv borg.sh[2651152]: repo: /backup/borg/srv id: 2022-08-08T18:32:00+02:00 hash:
Aug 08 18:33:30 srv borg.sh[2651152]: →→→ ended backup on srv
Aug 08 18:33:30 srv borg.sh[2651152]: →→→ starting backup on outscale
Aug 08 18:33:30 srv borg.sh[2651152]: →→→ create backup for [email protected]:/backup/srv
Aug 08 18:33:32 srv borg.sh[2652145]: M /etc/docker/domotique/data/hass/.storage/hacs.repositories
Aug 08 18:33:32 srv borg.sh[2652145]: M /etc/docker/domotique/data/hass/.storage/auth

동일한 로그 라인이 통과됩니다.journalctl

Aug 08 18:32:46 srv borg.sh[2651687]: Keeping archive (rule: weekly #4):       231d5f07-3453-46a5-a466-b8760196e120 Sun, 2022-07-03 23:00:11 [ab22320beda4d0f4ac247686adb39bd64533d93c9b02172e4299bf5f7e8ceee8]
Aug 08 18:32:46 srv borg.sh[2651687]: Keeping archive (rule: monthly #1):      3b280578-586f-4f62-80c1-b296aa8982c2 Thu, 2022-06-30 23:00:10 [067e23be4b7e33ec7b87f32603d5a05aa5e1f77e6dff17451b3d63db9130cafc]
Aug 08 18:32:48 srv borg.sh[2651687]: ------------------------------------------------------------------------------
Aug 08 18:32:48 srv borg.sh[2651687]:                        Original size      Compressed size    Deduplicated size
Aug 08 18:32:48 srv borg.sh[2651687]: Deleted data:               -3.54 GB             -1.61 GB             -1.33 MB
Aug 08 18:32:48 srv borg.sh[2651687]: All archives:                2.23 TB              1.82 TB            104.85 GB
Aug 08 18:32:48 srv borg.sh[2651687]:                        Unique chunks         Total chunks
Aug 08 18:32:48 srv borg.sh[2651687]: Chunk index:                  199025              7333955
Aug 08 18:32:48 srv borg.sh[2651687]: ------------------------------------------------------------------------------
Aug 08 18:33:32 srv borg.sh[2652145]: M /etc/docker/domotique/data/hass/.storage/hacs.repositories
Aug 08 18:33:32 srv borg.sh[2652145]: M /etc/docker/domotique/data/hass/.storage/auth

→→→로 시작하는 모든 것(그리고 접두사를 잊어버린 줄)은 repo에서 옵니다 echo.

답변1

선을 표시하는 방법을 찾았지만 차이점을 완전히 이해하지 못했습니다.

root@srv ~ [SIGINT]# journalctl -u borg -f
Aug 08 18:34:59 srv borg.sh[2652992]: All archives:                1.10 TB            806.57 GB             23.34 GB
Aug 08 18:34:59 srv borg.sh[2652992]:                        Unique chunks         Total chunks
Aug 08 18:34:59 srv borg.sh[2652992]: Chunk index:                  104061              5351569
Aug 08 18:34:59 srv borg.sh[2652992]: ------------------------------------------------------------------------------
Aug 08 18:34:59 srv borg.sh[2651152]: →→→ compact backup for [email protected]:/backup/srv
Aug 08 18:35:01 srv borg.sh[2651152]: repo: [email protected]:/backup/srv id: 2022-08-08T18:33:30+02:00 hash:
Aug 08 18:35:03 srv borg.sh[2651152]: →→→ ended backup on outscale
Aug 08 18:35:04 srv borg.sh[2651152]: →→→ ended borg backup at Mon Aug  8 18:35:04 CEST 2022

나는 전에 그것을 사용했다

root@srv ~ [SIGINT]# journalctl _COMM=borg -f
Aug 08 18:34:58 srv borg.sh[2652992]: Keeping archive (rule: daily #3):        16cccd33-5293-4a5f-8d36-35a46bfbe3b4 Wed, 2022-08-03 23:00:47 [5ae28fbaef906725950b9b672935c5c1ff9ebc8987c1fb8d96b3db65bbd6e375]
Aug 08 18:34:58 srv borg.sh[2652992]: Keeping archive (rule: daily #4):        226cc3ae-255e-4e24-977b-db1fa32fa741 Tue, 2022-08-02 23:00:55 [271d41a84227ffa104d18073e83760e190b3ec8a255852f7f23e404b50ead583]
Aug 08 18:34:58 srv borg.sh[2652992]: Keeping archive (rule: daily[oldest] #5): 2f43aa48-f6b4-4f69-b4da-d32a3ae3bcf7 Tue, 2022-08-02 16:01:05 [e8c9e47e7dac4f502c1259fbdb19a5783b6b081203dff7d4809ef763467d4c96]
Aug 08 18:34:59 srv borg.sh[2652992]: ------------------------------------------------------------------------------
Aug 08 18:34:59 srv borg.sh[2652992]:                        Original size      Compressed size    Deduplicated size
Aug 08 18:34:59 srv borg.sh[2652992]: Deleted data:                    0 B                  0 B                  0 B
Aug 08 18:34:59 srv borg.sh[2652992]: All archives:                1.10 TB            806.57 GB             23.34 GB
Aug 08 18:34:59 srv borg.sh[2652992]:                        Unique chunks         Total chunks
Aug 08 18:34:59 srv borg.sh[2652992]: Chunk index:                  104061              5351569
Aug 08 18:34:59 srv borg.sh[2652992]: ------------------------------------------------------------------------------

관련 정보