Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Running a GUI command from a root script

  1. #11
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    19,807
    Blog Entries
    14

    Default Re: Running a GUI command from a root script

    Run 2 cron jobs, where the root owned one writes the result to a file, i.e. "Succesful" or "Failed", a second cron job for the user, that does nothing but read the content of the file and - using whatever can do that - have it send that to the user desired. I've had to create something like that for a customer. But ....... within a month they asked me to remove the "annoying popup". FWIW, I used zenity for that IIRC.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    https://en.opensuse.org/openSUSE:Board#Members
    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  2. #12
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    26,680
    Blog Entries
    15

    Default Re: Running a GUI command from a root script

    Quote Originally Posted by Knurpht View Post
    Run 2 cron jobs, where the root owned one writes the result to a file, i.e. "Succesful" or "Failed", a second cron job for the user, that does nothing but read the content of the file and - using whatever can do that - have it send that to the user desired. I've had to create something like that for a customer. But ....... within a month they asked me to remove the "annoying popup". FWIW, I used zenity for that IIRC.
    Hi
    I just relay stuff out via google mail as a text message to my phone....
    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!

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

    Default Re: Running a GUI command from a root script

    Hey, thanks for all the replies!
    Some interesting and helpful thoughts there.
    Will have a bit of a think, and test, and see how I go.

    John.
    i5/8GB
    openSuse Leap15.1
    KDE Plasma 5.12.8 (and Gnome - In training!)
    Linux Counter 130995

  4. #14
    Join Date
    Jan 2017
    Location
    Nürnberg, Germany
    Posts
    177

    Default Re: Running a GUI command from a root script

    You could make your standard user’s graphical session available to root…
    Code:
    user ~$ xhost +root
    … then, in a script run by root, copy the authorization from the user to root and set your DISPLAY environment variable …
    Code:
    ~$ cp /home/user/.Xauthority /root/ # warning: don’t run a graphical session as root simultaneously
    ~$ export DISPLAY=:0.0 # display ID can vary depending on number of started X seats/sessions
    … finally, use something like kdialog for notifications:
    Code:
    ~$ kdialog --passivepopup 'hello from root' --title 'root says hi ... using kdialog'
    The list of stuff kdialog is capable of is quite interesting:
    Code:
    Usage: kdialog [options] [arg]
    KDialog can be used to show nice dialog boxes from shell scripts
    
    Options:
      -v, --version                     Displays version information.
      -h, --help                        Displays this help.
      --author                          Show author information.
      --license                         Show license information.
      --desktopfile <file name>         The base file name of the desktop entry for
                                        this application.
      --yesno <text>                    Question message box with yes/no buttons
      --yesnocancel <text>              Question message box with yes/no/cancel
                                        buttons
      --warningyesno <text>             Warning message box with yes/no buttons
      --warningcontinuecancel <text>    Warning message box with continue/cancel
                                        buttons
      --warningyesnocancel <text>       Warning message box with yes/no/cancel
                                        buttons
      --yes-label <text>                Use text as Yes button label
      --no-label <text>                 Use text as No button label
      --cancel-label <text>             Use text as Cancel button label
      --continue-label <text>           Use text as Continue button label
      --sorry <text>                    'Sorry' message box
      --detailedsorry <text> <details>  'Sorry' message box with expandable Details
                                        field
      --error <text>                    'Error' message box
      --detailederror <text> <details>  'Error' message box with expandable Details
                                        field
      --msgbox <text>                   Message Box dialog
      --inputbox <text> <init>          Input Box dialog
      --password <text>                 Password dialog
      --newpassword <text>              New Password dialog
      --textbox <file>                  Text Box dialog
      --textinputbox <text> <init>      Text Input Box dialog
      --combobox <text>                 ComboBox dialog
      --menu <text>                     Menu dialog
      --checklist <text>                Check List dialog
      --radiolist <text>                Radio List dialog
      --passivepopup <text> <timeout>   Passive Popup
      --icon <icon>                     Passive popup icon
      --getopenfilename                 File dialog to open an existing file
                                        (arguments [startDir] [filter])
      --getsavefilename                 File dialog to save a file (arguments
                                        [startDir] [filter])
      --getexistingdirectory            File dialog to select an existing directory
                                        (arguments [startDir])
      --getopenurl                      File dialog to open an existing URL
                                        (arguments [startDir] [filter])
      --getsaveurl                      File dialog to save a URL (arguments
                                        [startDir] [filter])
      --geticon                         Icon chooser dialog (arguments [group]
                                        [context])
      --progressbar <text>              Progress bar dialog, returns a D-Bus
                                        reference for communication
      --getcolor                        Color dialog to select a color
      --format <text>                   Allow --getcolor to specify output format
      --title <text>                    Dialog title
      --default <text>                  Default entry to use for combobox, menu and
                                        color
      --multiple                        Allows the --getopenurl and
                                        --getopenfilename options to return multiple
                                        files
      --separate-output                 Return list items on separate lines (for
                                        checklist option and file open with
                                        --multiple)
      --print-winid                     Outputs the winId of each dialog
      --dontagain <file:entry>          Config file and option name for saving the
                                        "do-not-show/ask-again" state
      --slider <text>                   Slider dialog box, returns selected value
      --calendar <text>                 Calendar dialog box, returns selected date
      --attach <winid>                  Makes the dialog transient for an X app
                                        specified by winid
      --embed <winid>                   A synonym for --attach
      --geometry <geometry>             Dialog geometry:
                                        [=][<width>{xX}<height>][{+-}<xoffset>{+-}<y
                                        offset>]
    Arguments:
      [arg]                             Arguments - depending on main option
    Cheers!

  5. #15
    Join Date
    Sep 2012
    Posts
    5,041

    Default Re: Running a GUI command from a root script

    Quote Originally Posted by unix111 View Post
    You could make your standard user’s graphical session available to root…
    Code:
    user ~$ xhost +root
    If "root" above refers to local user root - no, this command line does not make user's graphical session available to root. See "man xhost".

  6. #16
    Join Date
    Jan 2017
    Location
    Nürnberg, Germany
    Posts
    177

    Default Re: Running a GUI command from a root script

    Quote Originally Posted by arvidjaar View Post
    If "root" above refers to local user root - no, this command line does not make user's graphical session available to root. See "man xhost".
    You are correct, I copied a command from my bash history without trying it out first. This xhost command is superfluous anyway.

    It suffices for root to copy the .Xauthority file and then set the DISPLAY variable.
    Thanks for the correction, arvidjaar. Cheers!

  7. #17
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,153
    Blog Entries
    2

    Default Re: Running a GUI command from a root script

    Quote Originally Posted by unix111 View Post
    You are correct, I copied a command from my bash history without trying it out first. This xhost command is superfluous anyway.

    It suffices for root to copy the .Xauthority file and then set the DISPLAY variable.
    Thanks for the correction, arvidjaar. Cheers!
    As I noted earlier,
    using xhost is playing with fire... future changes may reveal more vulnerabilities and invalidate a use.
    Recommend simply sending an xmessage with display variable, should be simple, uncomplicated and not likely to be invalidated in the future...

    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!

Page 2 of 2 FirstFirst 12

Posting Permissions

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