R
R
rad_li2015-02-16 22:01:09
linux
rad_li, 2015-02-16 22:01:09

What is the correct way to send a message for notify-send via nc?

Ubuntu has a popup notify-send. You can use it like this:
notify-send "Система оповещения" "Пример работы"
The first block of text is the title of the notification, the second block is the message itself. Everything works, but it was necessary to use notifications over the network. To do this, I use the nc utility (netcat). On the receiving side, we listen to a specific port and send the received data to notify-send:
nc -l 10230 | { a=`cat` && notify-send $a; }
On the side of the notification sender:
echo "Заголовок" "Текст" | nc 192.168.10.2 10230
It also works, but there is a nuance. If there is a space in the header or body of the message, it throws an "Invalid number of options" error. That is, this will no longer work:

echo "Заголовок" "Текст сообщения" | nc 192.168.10.2 10230

Tell me how to be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2015-02-16
@rad_li

Send along with quotes on the sending side: echo '"Header" "Message text"'
On the receiving side, use the sent quotes as intended: { a=`cat` && eval "notify-send $a"; }

V
Vasily Angapov, 2015-02-16
@celebrate

Yes, the result is expected. In echo output, it is impossible to distinguish where one expression ended and another began if there were spaces in the expressions.
You can try to send two expressions over the network separated by a special character that will definitely not occur in either of them, for example:
On the sender:
On receiver:
IFS="%" while read ab; do notify-send $a $b; done < <(nc -l 10230)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question