You are not logged in.
Pages: 1
Hey everybody,
I was just wondering how to setup my fcrontab to send a notification on completion of commands, I've seen people saying DISPLAY=:0 needs to be put in as an environmental variable at the beginning but that doesn't seem to change anything.
Here is an example I've tried to setup, but it doesn't work as intended (i.e. it shows nothing).
@mail(no) 1 DISPLAY=:0 notify-send "This is a notify send fcron test"I would like to set it up for things like newsbeuter, in my case:
@mail(no) 3h notify-send "You have $(newsbeuter -x print-unread)"
OR
%daily,nice(7),mail(no) * 08-23 newsbeuter -q -x reload && notify-send "RSS feeds downloaded"The former here at least works manually, I don't really get what I'm doing wrong here but I suspect I'm missing something fundamental or simple.
Last edited by felixculpa (2017-08-06 04:39:56)
Offline
notify-send is just passing values to dbus. So, first of all, you need to tell dbus to connect to the right bus. You can find its address by examining DBUS_SESSION_BUS_ADDRESS environment variable and setting it to the same value. Therefore:
DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=your-address notify-send 'Foo bar'However, this will not suffice if the code is being run by user different from the target one, because dbus prohibits that. Here we have three options: the good, the bad and the ugly.
The good one is to write your own client that talks to dbus, presents the right credentials — and of course you have to set up dbus configuration to make this work — and sends the notification directly.
The bad one is to lie to dbus:
sudo -u your-target-user DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=your-address notify-send 'Foo bar'Of course, since this has to be run without interaction, it is implied that you have to set sudoers so the calling user has a right to call notify-send without a password. It’s pretty bad, because you need to give that additional permission and it’s kind of hacking around the problem.
The ugly one is ignoring dbus mess altogether. Setup a fifo file, the cron side appends lines with messages to it. On the user’s side you have a script that is constantly reading from that fifo and if it reads a line, it passes it to notify-send, which works in the local environment. The writing side should use \0 as the separator and the reading side should use xargs -0 -n 1 for reading to avoid both display errors and security vulnerabilities — don’t take this advice lightly if you’re going to implement this in shell script only.
In all three cases be sure to either not pass data from untrusted sources or sanitize it first.
Offline
The first option sounds like the only one I would be willing to go for. Is the variable simply what is listed by the following?
echo $DBUS_SESSION_BUS_ADDRESSFcrontab is being run as a normal user from my understanding, it sounds like it should work if I just put in the dbus variable. I will put in the variable and check back with you.
Edit: Yes! Putting in the proper DISPLAY and DBUS_SESSION_BUS_ADDRESS environmental variables at the top (or per line) work in getting the notifications to the desktop!
Last edited by felixculpa (2017-08-06 04:39:35)
Offline
Pages: 1