Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Running a GUI command from a root script

  1. #1
    Join Date
    Jun 2008
    Location
    Elliott Heads, Qld, Aus
    Posts
    199

    Default Running a GUI command from a root script

    Hi,
    Running a backup root cron job, that runs a script, to backup stuff across the network.
    What I would like to do is, when the script finishes (either successfully or not), to pop up a message in the "standard user" GUI (KDE plasma)
    Using
    Code:
    notify-send "Successful data backup"
    (or not...)
    and if run as the standard user, works fine, but obviously, when run using root cron - no message...

    Is it possible to get a message on the standard user desktop?
    Thanks.
    i5/8GB
    openSuse Leap15.1
    KDE Plasma 5.12.8 (and Gnome - In training!)
    Linux Counter 130995

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,002

    Default Re: Running a GUI command from a root script

    That is a fundamental problem because you are using a multi-user multi-session system. Thus to begin with at any moment in time there can be 0, 1 or more users running 0, 1 or more sessions of wich 0, 1 or more can be graphical (let us forget that those GUI sessions can use a lot of different desktop sets, saying it is KDE is of course not heard by the system).

    Also, when you (as a user) are working in a GUI session, you probably will not be very happy when other users (from other sessions, CLI or GUI) will be able to open windows on your screen, visable or unvisable, key-trackers or different. So that is forbidden by default (even when the user who tries to break into your session is root).

    Thus, even if there might be coming "solutions" for your problem, IMHO. it is opening a can of worms.
    Henk van Velden

  3. #3
    Join Date
    Jun 2008
    Location
    Elliott Heads, Qld, Aus
    Posts
    199

    Default Re: Running a GUI command from a root script

    Thought I might get a reply like that....
    Thanks...
    i5/8GB
    openSuse Leap15.1
    KDE Plasma 5.12.8 (and Gnome - In training!)
    Linux Counter 130995

  4. #4
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    26,670
    Blog Entries
    15

    Default Re: Running a GUI command from a root script

    Hi
    Why not use email? Anyway, consider switching from cron to systemd and timers/services, perhaps you can do some simple foo to check which users are active (loginctl) and send something or a gui notification;

    Code:
    loginctl list-sessions
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  5. #5
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,497
    Blog Entries
    3

    Default Re: Running a GUI command from a root script

    You could use "wall" (write to all) to send a message to any user with an open terminal session. Perhaps some desktops will trap this and turn the wall message into a desktop notification.
    openSUSE Leap 15.1; KDE Plasma 5;
    testing Leap 15.2Alpha

  6. #6
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,143
    Blog Entries
    2

    Default Re: Running a GUI command from a root script

    I'd imagine you can simply send a message to Display:0, maybe Display:1 which ought to display for any currently logged in User no matter who they are and wouldn't require any special permissions beyond your root.
    Something like xmessage described in the following... and just a note, regarding one of the other suggestions to the post using xhost, I avoid that whenever possible because it's living on the edge whether what you're doing is secure or not so has been updated within the past few years so many former uses don't work today

    https://superuser.com/questions/3099...ogged-into-x11


    If you really want to identify any logged in Users, I came across this interesting article, "w" might be useful.

    https://www.thegeekstuff.com/2009/03...-linux-system/

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  7. #7
    Join Date
    Sep 2012
    Posts
    5,027

    Default Re: Running a GUI command from a root script

    Quote Originally Posted by hornetster View Post
    Is it possible to get a message on the standard user desktop?
    One possibility is to run system-to-user D-Bus bridge as part of user desktop and use standard notifications API. Example implementation is described here (sorry, German, was the first hit): https://wiki.debianforum.de/Desktop-...e_mittels_dbus

  8. #8
    Join Date
    Jan 2014
    Location
    Erlangen
    Posts
    966

    Default Re: Running a GUI command from a root script

    Quote Originally Posted by hcvv View Post
    That is a fundamental problem because you are using a multi-user multi-session system. Thus to begin with at any moment in time there can be 0, 1 or more users running 0, 1 or more sessions of wich 0, 1 or more can be graphical (let us forget that those GUI sessions can use a lot of different desktop sets, saying it is KDE is of course not heard by the system).

    Also, when you (as a user) are working in a GUI session, you probably will not be very happy when other users (from other sessions, CLI or GUI) will be able to open windows on your screen, visable or unvisable, key-trackers or different. So that is forbidden by default (even when the user who tries to break into your session is root).

    Thus, even if there might be coming "solutions" for your problem, IMHO. it is opening a can of worms.
    'mail userxyz' always works unless somebody has tinkered with mail.
    AMD Athlon 4850e (2009), openSUSE 13.1, KDE 4, Intel i3-4130 (2014), i7-6700K (2016), i5-8250U (2018), openSUSE Tumbleweed, KDE Plasma 5

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,002

    Default Re: Running a GUI command from a root script

    Quote Originally Posted by karlmistelberger View Post
    'mail userxyz' always works unless somebody has tinkered with mail.
    That is suggested above, but it is not what the user asked for. I have no idea if it fullfills his whishes (the particular usr(s) must have her/his/their e-mail program running and a not to long time step between checking, etc), but it is certainly one of the easier sulutions (when not the easiest).
    Henk van Velden

  10. #10
    Join Date
    Jan 2014
    Location
    Erlangen
    Posts
    966

    Default Re: Running a GUI command from a root script

    Quote Originally Posted by hcvv View Post
    That is suggested above, but it is not what the user asked for. I have no idea if it fullfills his whishes (the particular usr(s) must have her/his/their e-mail program running and a not to long time step between checking, etc), but it is certainly one of the easier sulutions (when not the easiest).
    To pop up a message window isn't nice and doing so can have drastic side effects:

    It turned out to be an issue with the Linux implementation of tray messages (the java.awt.TrayIcon class). The implementation is simply put **** on Linux and Oracle hasn't put any efforts into improving it over the years. There are multiple bug reports filed on it (various stuff, not this specific crash). I could get it to work by calling the buggy TrayIcon.displayMessage() call on the JavaFX thread, but only if I was using the Darcula L&F (Look and feel). If I switched to the GTK+ L&F, it hung again. My workaround to this was to simply dump the printing of tray messages on Linux.
    http://jalbum.net/forum/thread.jspa?...55430&tstart=0
    AMD Athlon 4850e (2009), openSUSE 13.1, KDE 4, Intel i3-4130 (2014), i7-6700K (2016), i5-8250U (2018), openSUSE Tumbleweed, KDE Plasma 5

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •