2

I run via a systemd timer a shell script that starts some programs (they display some output) and uses echo to provide some feedback.

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
(...)
  • When starting the script interactively I see both outputs (the program and echo ones) through journalctl.

  • When running it via the timer only the program output is displayed.

I understand that the latter is a non-interactive run, but since the program output someone makes its way to journalctl so what not the timer?

Is there a way to make such feedback outputs from the script appear?


Below is a comparison of what is output via systemctl and journalctl when starting the script ad hoc via sytemctl start borg. I now wonder whether the fact that this is a "two-stage" script (bash running borg.sh which itself runs python behind the scenes) could be a reason for the filtered output (just a wild guess)

Output from 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

The same log lines via 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

Everything that starts with →→→ (and the repo line I forgot to prefix) come from an echo.

2
  • the standard output from the shell script should get to journalctl just as well as standard output from whatever is run in (...) so I'm not sure why your echo output is not showing up. maybe try just a date or removing the fancy unicode characters? Commented Aug 8, 2022 at 16:11
  • @thrig I tried your suggestion, same result. It gave me the idea to update my question with a view of the same log lines from systemctl and journalctl perspectives. Commented Aug 8, 2022 at 16:41

1 Answer 1

0

I found how to have the lines appear, but do not fully understand the difference:

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

I was previously using

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]: ------------------------------------------------------------------------------

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.