• A desktop notification from a background root script

    From Teemu Likonen@3:633/10 to All on Monday, March 02, 2026 08:50:01
    I have a systemd timer and service that runs my backup script daily. The
    script runs on root privileges.
    If the backup script notices an error I would like to report the error
    as a notification in normal user's desktop. In the past this worked with
    "wall" command in the backup script:
    wall "The backup failed. See the journal for more info."
    KDE Plasma desktop has a background service which delivers "wall"
    messages as desktop notifications. This doesn't work anymore. "wall"
    messages doesn't show in desktop even though the background service is
    running.
    I don't know when it stopped working but my first guess is that some of
    those features have not been ported to Wayland yet. I switched from X11
    to Wayland a couple of months ago (and it's great; I'm not going back).
    I also upgraded from Debian 12 to 13 last summer.
    So, the general question is: how could a background root script give a
    desktop notification for the current / all users?
    --
    /// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
    // OpenPGP: DD3B8E8ABD28B98176E6A7CCCC9A5E615FCC1D93
    / old key: 6965F03973F0D4CA22B9410F0F2CAE0E07608462


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From didier gaumet@3:633/10 to All on Monday, March 02, 2026 09:40:01

    Hello,

    wall is now provided by the bsdutils package (priority: required): is it installed?

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Michel Verdier@3:633/10 to All on Monday, March 02, 2026 12:40:01
    On 2026-03-02, Teemu Likonen wrote:

    I don't know when it stopped working but my first guess is that some of
    those features have not been ported to Wayland yet. I switched from X11
    to Wayland a couple of months ago (and it's great; I'm not going back).
    I also upgraded from Debian 12 to 13 last summer.

    You could look at this bug report about wall https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1115259

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Teemu Likonen@3:633/10 to All on Monday, March 02, 2026 13:50:01
    * 2026-03-02 12:38:09+0100, Michel Verdier wrote:
    You could look at this bug report about wall https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1115259
    That is probably saying that "wall" will not be fixed for the operation.
    I'm not fixed to "wall". We can ditch it. The general question is: How
    could a background root script give a desktop notification for the
    current / all users?
    --
    /// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
    // OpenPGP: DD3B8E8ABD28B98176E6A7CCCC9A5E615FCC1D93
    / old key: 6965F03973F0D4CA22B9410F0F2CAE0E07608462


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Franco Martelli@3:633/10 to All on Monday, March 02, 2026 14:30:02
    On 02/03/26 at 08:46, Teemu Likonen wrote:
    So, the general question is: how could a background root script give a desktop notification for the current / all users?

    Have you tried "notify-send"? It is provided by the "fyi" package.

    kind regards.
    --
    Franco Martelli

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Michel Verdier@3:633/10 to All on Monday, March 02, 2026 15:30:01
    On 2026-03-02, Teemu Likonen wrote:

    I'm not fixed to "wall". We can ditch it. The general question is: How
    could a background root script give a desktop notification for the
    current / all users?

    If you are on a single system you could use xmessage from the package
    x11-utils

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Teemu Likonen@3:633/10 to All on Monday, March 02, 2026 16:20:01
    * 2026-03-02 14:29:24+0100, Franco Martelli wrote:
    On 02/03/26 at 08:46, Teemu Likonen wrote:
    So, the general question is: how could a background root script give
    a desktop notification for the current / all users?

    Have you tried "notify-send"? It is provided by the "fyi" package.
    Not that one (before) but those notification daemons tend to require the
    same user. So does "fyi":
    $ sudo fyi Title Message
    error: failed to connect: /usr/bin/dbus-launch terminated abnormally
    without any error message
    So root can't easily send notifications for other users.
    Maybe I'll make my backup script's error messages go to a specific text
    file and write a user's systemd path unit that triggers on changes of
    that file. The triggered service would print "fyi" notification with
    file's content as the message. Something like that.
    But a good operating system should have an easy uniform way for any
    maintenance task to inform desktop user. Maybe systemd people will come
    up with something some day. They are good at thinking of big picture.
    --
    /// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
    // OpenPGP: DD3B8E8ABD28B98176E6A7CCCC9A5E615FCC1D93
    / old key: 6965F03973F0D4CA22B9410F0F2CAE0E07608462


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Franco Martelli@3:633/10 to All on Monday, March 02, 2026 21:00:01
    On 02/03/26 at 08:46, Teemu Likonen wrote:
    KDE Plasma desktop has a background service which delivers "wall"
    messages as desktop notifications. This doesn't work anymore.

    Do you refer to "kwrited"? "kwrited" is for X11 maybe you could ask to
    KDE guys whether there is something for Wayland.

    Kind regards.
    --
    Franco Martelli

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Franco Martelli@3:633/10 to All on Monday, March 02, 2026 21:00:01
    On 02/03/26 at 16:18, Teemu Likonen wrote:
    Not that one (before) but those notification daemons tend to require the
    same user. So does "fyi":

    $ sudo fyi Title Message
    error: failed to connect: /usr/bin/dbus-launch terminated abnormally
    without any error message

    So root can't easily send notifications for other users.

    Yes, but if you want to ditch "wall" then you could try to play with
    this code in your script:

    uid=1000 gid=1000
    setpriv --reuid "$uid" --regid "$gid" --init-groups \
    env XDG_RUNTIME_DIR=/run/user/"$uid" DISPLAY=:0 XDG_CURRENT_DESKTOP=KDE
    fyi TEST test

    Of course you have to change 1000 if your user id is different, the "id" command will tell you which value of uid and gid to use. Also the
    DISPLAY value matters. Here it works, but I'm on KDE+X11, not Wayland sorry.

    Unlike the "wall" command, you will have to write a "setpriv" command
    for each user you want to notify if something goes wrong in the script.

    Kind regards.
    --
    Franco Martelli

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jan Claeys@3:633/10 to All on Thursday, March 05, 2026 16:20:02
    On Mon, 2026-03-02 at 09:46 +0200, Teemu Likonen wrote:
    So, the general question is: how could a background root script give
    a desktop notification for the current / all users?

    If no better & more generic solution pops up, you could have the backup
    script write its "message" to a file in a specific location, and then
    in the desktop user session watch that file for changes, sending its
    content to the notify daemon (which can be done with a simple script & 'inotifywait'). For your personal use that might be sufficient,
    although a more generic solution would be nice...


    --
    Jan Claeys

    (please don't CC me when replying to the list)

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Teemu Likonen@3:633/10 to All on Thursday, March 05, 2026 18:50:01
    * 2026-03-05 16:04:53+0100, Jan Claeys wrote:
    On Mon, 2026-03-02 at 09:46 +0200, Teemu Likonen wrote:
    So, the general question is: how could a background root script give
    a desktop notification for the current / all users?

    If no better & more generic solution pops up, you could have the backup script write its "message" to a file in a specific location, and then
    in the desktop user session watch that file for changes, [...]
    I did that. A systemd .path unit watches for changes in the file and
    triggers a .service unit for showing the notification. Simple enough but
    indeed there's a need for a good generic solution.
    --
    /// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
    // OpenPGP: DD3B8E8ABD28B98176E6A7CCCC9A5E615FCC1D93
    / old key: 6965F03973F0D4CA22B9410F0F2CAE0E07608462


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From tomas@3:633/10 to All on Thursday, March 05, 2026 19:10:01
    On Thu, Mar 05, 2026 at 07:42:05PM +0200, Teemu Likonen wrote:
    [...]
    I did that. A systemd .path unit watches for changes in the file and
    triggers a .service unit for showing the notification. Simple enough but indeed there's a need for a good generic solution.
    Uh-oh. That's what notification in the age of systemd has come to.
    Cheers
    --
    tom s


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Darac Marjal@3:633/10 to All on Thursday, March 05, 2026 21:50:01
    The ArchWiki (https://wiki.archlinux.org/title/Desktop_notifications#Send_notifications_to_all_graphical_users)
    offers this snippet:

    # for id in $(loginctl list-sessions -j | jq -r '.[] | .session')ÿ; do
    if [[ $(loginctl show-session $id --property=Type) =~ (wayland|x11) ]]ÿ; then
    systemd-run --machine=$(loginctl show-session $id --property=Name --value)@.host --user \
    notify-send 'Hello world!' 'This is an example notification.'
    fi
    done

    On 02/03/2026 07:46, Teemu Likonen wrote:
    I have a systemd timer and service that runs my backup script daily. The script runs on root privileges.

    If the backup script notices an error I would like to report the error
    as a notification in normal user's desktop. In the past this worked with "wall" command in the backup script:

    wall "The backup failed. See the journal for more info."

    KDE Plasma desktop has a background service which delivers "wall"
    messages as desktop notifications. This doesn't work anymore. "wall"
    messages doesn't show in desktop even though the background service is running.

    I don't know when it stopped working but my first guess is that some of
    those features have not been ported to Wayland yet. I switched from X11
    to Wayland a couple of months ago (and it's great; I'm not going back).
    I also upgraded from Debian 12 to 13 last summer.

    So, the general question is: how could a background root script give a desktop notification for the current / all users?



    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Teemu Likonen@3:633/10 to All on Friday, March 06, 2026 08:10:01
    * 2026-03-05 20:41:00+0000, Darac Marjal wrote:
    The ArchWiki (https://wiki.archlinux.org/title/Desktop_notifications#Send_notifications_to_all_graphical_users)
    offers this snippet:

    # for id in $(loginctl list-sessions -j | jq -r '.[] | .session')ÿ; do
    if [[ $(loginctl show-session $id --property=Type) =~ (wayland|x11) ]]ÿ; then
    systemd-run --machine=$(loginctl show-session $id --property=Name --value)@.host --user \
    notify-send 'Hello world!' 'This is an example notification.'
    fi
    done
    Thank you! I knew that the systemd guys had all the basic pieces
    together already. Now they only need to write the final pieces of the
    new /usr/bin/wall-for-the-desktop-generation tool. I wrote my own in the
    Fish shell:
    #!/usr/bin/fish
    set notify_program /usr/bin/fyi
    set notify_args $argv
    for session in (loginctl list-sessions --no-legend | cut -d' ' -f1)
    set -l type (loginctl show-session $session -p Type --value)
    if string match -qr '^(wayland|X11)$' $type
    set -l user (loginctl show-session $session -p Name --value)
    systemd-run --user -M $user@ -- $notify_program $notify_args
    end
    end
    (Fish shell does not have sh-like word splitting so similar quoting is
    not needed.)
    --
    /// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
    // OpenPGP: DD3B8E8ABD28B98176E6A7CCCC9A5E615FCC1D93
    / old key: 6965F03973F0D4CA22B9410F0F2CAE0E07608462


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jan Claeys@3:633/10 to All on Saturday, March 14, 2026 14:10:01
    On Thu, 2026-03-05 at 20:41 +0000, Darac Marjal wrote:
    if [[ $(loginctl show-session $id --property=Type) =~ (wayland|
    x11) ]]; then

    Why the check for wayland/X11 ?

    Better to just try to send a notification and let it fail for sessions
    that don't support it rather than sending nothing to a session that is
    not wayland or X11 but still supports notifications. (I'm sure not all X11/wayland sessions support it either...)


    --
    Jan Claeys

    (please don't CC me when replying to the list)

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)