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

Thread: send message to user's GUI through command line

  1. #1
    Join Date
    Dec 2009
    Beans
    319
    Distro
    Ubuntu 12.04 Precise Pangolin

    send message to user's GUI through command line

    presently I am running Ubuntu 10.04 on multiple old PCs in my house. if it were just MY PCs I would be fine, however, the problem comes in when I have to factor in people who are Windows all the way and can't figure out Update Manager. So to avoid the headaches I am remoting into their computers via ssh, if there is a kernel update that requires a restart I normally just restart their computer for them as well. However before i do that I run "who" to see if they are on. If they are I cannot restart their computer.

    I would LIKE to be able to, from the command line, send a message to their GUI informing them they will need to restart their computer after they have concluded their business for the time being. Is this possible? so we are clear, I have my own account with sudoer permissions to administrate this account. I would be sending the message from my account (on the CLI) to their account (preferably a popup window in their GUI).

  2. #2
    Join Date
    May 2010
    Location
    uk
    Beans
    9,249
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: send message to user's GUI through command line

    Hi

    I have read, but never tried, that samba can do this for you.

    Code:
    echo "Going for reboot now" | smbclient -M <cmputer_name>
    Now this i do know for sure: You can get the computer names using

    Code:
    nbtscan 192.168.0.0/24
    This will scan the class C subnet 192.168.0.0/24 and you will have to change as appropriate for your network.

    It's in the package...

    Code:
    matthew-S206:/home/matthew % apt-cache search nbtscan
    nbtscan - A program for scanning networks for NetBIOS name information
    matthew-S206:/home/matthew %
    You can get extra information using

    Code:
    nmblookup -A 192.168.0.104
    Tell us how it goes.

    EDIT:

    Did i misunderstand you ? Are they on Windows or Linux machines, as the above solution if for sending messages to Windows machines from a Linux box.

    If your ssh'ing into a linux box to reboot it then something like this should work (assuming you have notify-send)

    Code:
    DISPLAY=:0.0 notify-send "REBOOTING IN 5 MINUTES" "Your PC will be rebooted in 5 Minutes. Please save all your files"
    Kind regards
    Last edited by matt_symes; March 25th, 2013 at 03:43 PM.
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

    Thinking about becoming an Ubuntu Member?

  3. #3
    Join Date
    Dec 2009
    Beans
    319
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: send message to user's GUI through command line

    trying the notify send worked fine on my computer, however when I ssh'd into the other computer and tried (had to install the program first) I got this message

    DISPLAY=:0.0 notify-send "Your Operating system has been updated. when you have finish with your business, please restart the computer. Thank you."
    libnotify-Message: Unable to get session bus: /bin/dbus-launch terminated abnormally with the following error: No protocol specified
    Autolaunch error: X11 initialization failed.




    ** (notify-send:5797): CRITICAL **: dbus_g_proxy_connect_signal: assertion `DBUS_IS_G_PROXY (proxy)' failed


    ** (notify-send:5797): CRITICAL **: dbus_g_proxy_connect_signal: assertion `DBUS_IS_G_PROXY (proxy)' failed


    ** (notify-send:5797): CRITICAL **: dbus_g_proxy_call: assertion `DBUS_IS_G_PROXY (proxy)' failed
    libnotify-Message: Unable to get session bus: /bin/dbus-launch terminated abnormally with the following error: No protocol specified
    Autolaunch error: X11 initialization failed.




    ** (notify-send:5797): CRITICAL **: dbus_g_proxy_disconnect_signal: assertion `DBUS_IS_G_PROXY (proxy)' failed


    ** (notify-send:5797): CRITICAL **: dbus_g_proxy_disconnect_signal: assertion `DBUS_IS_G_PROXY (proxy)' failed
    thank you for your help thus far

  4. #4
    Join Date
    May 2010
    Location
    uk
    Beans
    9,249
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: send message to user's GUI through command line

    Hi

    Are you logging in as the same user as the user who is logged on ?

    I assume this is a session dbus error but i may be wrong.

    Kind regards
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

    Thinking about becoming an Ubuntu Member?

  5. #5
    Join Date
    Dec 2009
    Beans
    319
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: send message to user's GUI through command line

    no, my own account.

  6. #6
    Join Date
    Apr 2012
    Beans
    7,256

    Re: send message to user's GUI through command line

    I'm not able to recreate your exact error, but I'd expect you'd either need to grab the remote user's DBUS_SESSION_BUS_ADDRESS or at least their Xauthority - the old school way would probably be to have the remote user open up their session authority using 'xhost +', however I think it's recommended to avoid that if possible

    FWIW this works for me (it assumes your ssh user can read the remote user's $HOME/.Xauthority using sudo):

    Code:
    steeldriver@htpc-01:~$ xauth list    # we are logged in via ssh and don't have any valid Xauthority cookies 
    steeldriver@htpc-01:~$
    steeldriver@htpc-01:~$ sudo cat /home/remote-user/.Xauthority | xauth merge -
    steeldriver@htpc-01:~$ xauth list    # now we should have a cookie for the active remote display
    htpc-01/unix:0  MIT-MAGIC-COOKIE-1  c7eb54429f6b730cd89eea184c352bfc
    steeldriver@htpc-01:~$
    steeldriver@htpc-01:~$ DISPLAY=:0 notify-send test 'This is a test'
    steeldriver@htpc-01:~$
    It's probably not strictly necessary, but you can revoke the grabbed Xauthority after with
    Code:
    steeldriver@htpc-01:~$ xauth remove htpc-01/unix:0

  7. #7
    Join Date
    May 2010
    Location
    uk
    Beans
    9,249
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: send message to user's GUI through command line

    Hi

    no, my own account.
    That'll be a problem then.

    You'll certainly want a X server cookie so follow steeldriver's post to get the users X cookie.

    Post back on how you get on.
    the old school way would probably be to have the remote user open up their session authority using 'xhost +', however I think it's recommended to avoid that if possible
    I believe it's classed as a security risk.

    Kind regards
    Last edited by matt_symes; March 25th, 2013 at 11:46 PM.
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

    Thinking about becoming an Ubuntu Member?

  8. #8
    Join Date
    Dec 2009
    Beans
    319
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: send message to user's GUI through command line

    steel's tutorial fails at the
    Code:
    sudo cat /home/remoteuser/.Xauthority \ xauth merge -
    there is no .Xauthority in the user's home directory
    Last edited by matt_symes; March 26th, 2013 at 10:43 AM.

  9. #9
    Join Date
    Apr 2012
    Beans
    7,256

    Re: send message to user's GUI through command line

    My apologies, I just checked and that command doesn't work if the ssh user doesn't have an existing .Xauthority file to merge the remote session's cookie into

    You can either create an empty ~/.Xauthority (mode should be 600 i.e. -rw-------) or try this which I *think* will create the file if it doesn't already exist

    Code:
    sudo cat /home/remote-user/.Xauthority | xauth -f ~/.Xauthority merge -

  10. #10
    Join Date
    Dec 2009
    Beans
    319
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: send message to user's GUI through command line

    Code:
    sudo cat /home/<remote-user>/.Xauthority | xauth -f ~/.Xauthority merge -
    xauth:  creating new authority file /home/me/.Xauthority
    cat: /home/<remote-user>/.Xauthority: No such file or directory
    xauth: (argv):1:  unable to read any entries from file "(stdin)"
    no joy

    what account should own the .Xauthority file?

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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