Trying to send system notifications via SSH to computers on LAN. [SOLVED]
I have two computers on my LAN, one running Ubuntu Jaunty. I want to be able to send notifications to the Ubuntu computer using the notify-send command, so that messages I write appear on screen in the little bubbles.
The basic structure is: Code:
notify-send "MESSAGE HERE." I can SSH into any computer with X forwarding on, as such Code:
ssh -X user@host Code:
DISPLAY=:0 notify-send "MESSAGE HERE." Code:
alias chat='DISPLAY=:0 notify-send' Code:
chat "MESSAGE HERE." Rather than having a two-step process (logging in via SSH and then sending the message), I'm trying to write a one-liner script that will do the job all in one shot. If I'm at my local terminal prompt, I can issue the command Code:
ssh -X user@host 'DISPLAY=:0 notify-send "MESSAGE HERE"' The problem I'm having is setting the double-quoted text as a variable so that I can change it as necessary and still use the same structure as the alias that I showed above. The basic idea here, in case I haven't elaborated enough, is to type Code:
chat "MESSAGE HERE." Can anyone point me in the right direction? |
A bash script?
Code:
#!/bin/sh |
Quote:
Code:
$ ./chat.sh "This is a test." Trying to send a blank notify-send locally produces the same error Code:
$ notify-send "" |
The $message variable needs to be evaluated before the command is sent, and not literally as '$message'. Also the message part of the notify-send command needs to be a single argument.
examples: message="this is only a test" ssh qosmio "DISPLAY=:0 notify-send -i gtk-icon-warning \"$message\"" also ssh qosmio 'DISPLAY=:0 notify-send -i gtk-icon-warning ''"'$message'"' The single & double quotes may be hard to make out: ...warning sq sq dq sq $message sq dq sq |
Quote:
Also, the message changes every time I want to send one. It might be as simple as "Please reboot," or, "Internet will be offline 15 mins formaintenance." Having to open, edit, save, and then execute a script is just as bad (if not worse) than having to log in remotely, send a message, and then sign back out. I guess I could write a second script (or work it into this one) using echo & sed that both changes the message and executes the chat script.. but that seems a convoluted way of doing it. |
I just used $message for my testing. You could use $1 instead.
Code:
#!/bin/sh |
Quote:
Thanks for the help... I can't believe how sometimes the simplest of things cause the most problems. |
Quote:
Have you been able to write another users screen besides yourself with this method? Maybe the command your looking for is: Code:
echo "hello" | wall |
Quote:
Code:
#!/bin/bash To answer your question, micxz, you can use SSH to execute single commands on remote hosts. The beauty of a simple script like this is that you an use aliases inside of it. For example, say I have the following aliases:
|
I don't think you understand what I'm asking. For example if you are sending a message to user "bob" on "host1" and you send the command:
Code:
ssh -X bob@host1 "DISPLAY=:0 notify-send "message" If you try to send this same message to user "joe" on "host1" "joe" may have a different $DISPLAY set and does have different xauth cookies set. So "joe" won't see the message. The reason the first example works is because "bob" has the same xauth cookies set as user "bob" so of course he can write to his own screen. I think the only way to be able to display this popup to all users on all screens is to have a script find out who's logged in and get the env for all users running X or logged via ssh -X and get they're xauth cookie and DISPLAY from env and send a message to each using this info. I know sound like allot but I think wall does this and will notify users even if they are not using X. |
Oh, ok, yeah, I see what you're saying now. I suppose that's the reason it does work - because bob is logged in and I ssh in as bob. I haven't tried it as a different user. I would imagine it would work as root no matter what, but having RSA & DSA SSH keys laying around for a root account probably isn't the smartest thing a person could do. I think a limited user group and/or account could be created with specific permissions for accessing notify-osd or zenity or wall or whatever on any display, regardless of user. (Probably the group already exists in Ubuntu - admin? plugdev? Beats me...)
I don't know about all that, man. All I do know is this one does what I need and it works the way I want it to. My wife is the main recipient of the usefulness of this. She's running Ubuntu 9.04. If she has a terminal open for anything, chances are I'm looking over her shoulder giving her tips on what to do. She never shuts down X or uses the TTYs. I'll be using this to send her messages like "I just updated XXXXX, please restart the program," or, "I just installed your new kernel. Please reboot," and such things. As far as anything else, if you'd like, I'd help you put together something (as much as I could, anyway..). Just start a new thread with an idea and basis and we'll go from there. |
Quote:
Quote:
Quote:
Quote:
Quote:
http://www.linuxquestions.org/questi...o-work-741489/ |
micxz: Yes you are right. It assumes DISPLAY :0 is being used by the user, and you need ssh <user>@<host> if you are sending it to someone else. My main point was that you need to be careful how you escape the variable with the message. Otherwise there are too many arguments for ssh or the notify command. The OP was having a problem sending a command in one-shot, using ssh with a command argument. In other words, not having to log in and log out. This is tricky because the variable needs to be evaluated before ssh sends it, but you can't have the wrong number of arguments to ssh. When run in the target, the double quotes are needed so that the shell running on the remote machine doesn't break up the message.
Using two variables (and arguments to the send script) $summary and $body might look better. |
jschiwal your right as well. Maybe I was talking the thread to far to cover other factors that I now realize the OP does not need.
|
All times are GMT -5. The time now is 06:16 AM. |