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

Thread: Bash script (or alias) using ssh & notify-send

  1. #1
    Join Date
    Feb 2007
    Location
    Detroit, Michigan
    Beans
    692

    Bash script (or alias) using ssh & notify-send [SOLVED]

    I have two computers on a LAN both using Jaunty.

    I "administer" both computers and have passwordless ssh access to both systems. I'm trying to write a script (or an alias) so that I can send notification bubbles to the computers remotely. Issuing the command
    Code:
    ssh -X user@host 'DISPLAY=:0 notify-send "TEST MESSAGE."'
    at a local terminal works like a charm - the notification bubble containing the message appears on the remote screen.

    Since the text "TEST MESSAGE." is just an example used here, and the message I will want to send will vary every time, "TEST MESSAGE." has to be made into a variable. If I create an alias on each system, such as
    Code:
    alias chat='DISPLAY=:0 notify-send'
    I can log in remotely, and at the remote prompt, simply enter
    Code:
    chat "FOO BAR."
    and the quoted text, along with the quotes, is appended to the end of the aliased command.

    In trying to create an alias or a script - let's name it 'chat' in either case - that resides locally but uses SSH to execute a remote command, setting the variable is proving to be quite a headache. Since the structure should be the same as the above example, I have to pass along the double quotes as input. In trying to do so, I keep getting errors such as, "Invalid number of options," or, "No summary specified."

    In using an alias, structured like so
    Code:
    alias chat='ssh user@host DISPLAY=:0 notify-send'
    I can send messages to the remote computer and have them appear on screen, but only if they are one or two words long - three words produces the "Invalid number of options" error.

    In using a script, I have to assign the "QUOTED MESSAGE" to a variable, otherwise I get the "No summary specified" error - the same error as if you went to a local prompt and typed
    Code:
    notify-send ""
    without any text between the quotes.

    In trying to nest the variable inside those quotes, like this
    Code:
    ssh user@host DISPLAY=:0 notify-send "$1"
    again produces errors. Exchanging the $1 variable for $@ causes the error to switch from one to the other.

    Can anyone offer me pointers as to how I would pass a quoted string as a variable into a simple one-liner like this?
    Last edited by detroit/zero; August 15th, 2009 at 02:21 PM. Reason: [SOLVED]
    I switched to Windows because of all the disappointment Linux brought me.

  2. #2
    Join Date
    Jan 2008
    Beans
    4,757

    Re: Bash script (or alias) using ssh & notify-send

    Code:
    function chat { ssh -X user@host 'DISPLAY=:0 notify-send "$@"'; }
    Give that a whirl.

    Regards
    Iain

  3. #3
    Join Date
    Feb 2007
    Location
    Detroit, Michigan
    Beans
    692

    Re: Bash script (or alias) using ssh & notify-send

    Quote Originally Posted by tinivole View Post
    Code:
    function chat { ssh -X user@host 'DISPLAY=:0 notify-send "$@"'; }
    Give that a whirl.

    Regards
    Iain
    No go. The script executes without errors, but no message is displayed on the remote screen.
    I switched to Windows because of all the disappointment Linux brought me.

  4. #4
    Join Date
    Feb 2007
    Location
    Detroit, Michigan
    Beans
    692

    Re: Bash script (or alias) using ssh & notify-send

    The final, working copy:
    Code:
    #!/bin/bash
    #
    #Send messages through SSH to remote hosts' notify-osd
    #
    message="$@"
    ssh -X user@host "DISPLAY=:0 notify-send \"$message\""
    exit
    I was close, I guess. Just had to get the quotes & escapes right.
    I switched to Windows because of all the disappointment Linux brought me.

  5. #5
    Join Date
    Jul 2009
    Beans
    8

    Angry Re: Bash script (or alias) using ssh & notify-send

    But running this script gives me error that command notify-send not found.

    #!/bin/bash
    #
    #Send messages through SSH to remote hosts' notify-osd
    #
    message="$@"
    ssh -X user@host "DISPLAY=:0 notify-send \"$message\""
    exit

  6. #6
    Join Date
    Feb 2007
    Location
    Detroit, Michigan
    Beans
    692

    Re: Bash script (or alias) using ssh & notify-send

    So install it.
    Code:
    sudo apt-get install notify-send
    I switched to Windows because of all the disappointment Linux brought me.

  7. #7
    Join Date
    Mar 2009
    Beans
    37
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Bash script (or alias) using ssh & notify-send

    E: Couldn't find package notify-send

  8. #8
    Join Date
    Feb 2007
    Location
    Detroit, Michigan
    Beans
    692

    Re: Bash script (or alias) using ssh & notify-send

    Ah, I see. The package has changed. notify-send is now provided by libnotify-bin.

    A simple Google search would have told you as much.
    I switched to Windows because of all the disappointment Linux brought me.

  9. #9
    Join Date
    Oct 2009
    Beans
    10

    Re: Bash script (or alias) using ssh & notify-send

    Thanks Detroit/Zero very useful!

  10. #10
    Join Date
    Jun 2008
    Location
    Ballard
    Beans
    2,409
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Bash script (or alias) using ssh & notify-send

    I keep seeing this solution come up but I am getting a dbus error when I try to run notify-send remotely. I am trying to display the message on whichever user happens to be signed in. Is that the problem? Or is it something else?

    Code:
    ssh user@remote 'DISPLAY=:0 notify-send "HELLO" "Some stuff."'
    "We're all in this together, kid." --H. Tuttle (a.k.a. H. Buttle)
    "Maybe it's a layer 8 problem." --thatguruguy
    A High-Tech Blech!

Page 1 of 2 12 LastLast

Tags for this Thread

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
  •