You are not logged in.

#1 2014-11-02 13:37:36

netpumber
Member
Registered: 2009-09-20
Posts: 134

systemd timer could not run in X a script with notify-send

Hello.
I created a simple .timer file with these inside:

[Unit]
Description=Script to remind me backup every month

[Timer]
# Time to wait after booting before we run first time
OnBootSec=10min
# Time between running each consecutive time
OnUnitActiveSec=1minute
Unit=timer_backup.service
Persistent=true

[Install]
WantedBy=multi-user.target

and a .service file with:

[Unit]
Description=Timer script to remind me for backup

[Service]
Type=simple
ExecStart=/path/to/bu.sh

the bu.sh has

notify-send -u critical -t 999999999 -c backup "System backup reminder" "It's time to backup the whole system"

The problem is that it never visualize the notify box.
How can i run a X application in the activated user monitor ? Also tried to use xuserrun but it couldn't find any enable screen although the loginctl returns the session of my user.

Offline

#2 2014-11-02 14:09:33

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,394

Re: systemd timer could not run in X a script with notify-send

1 - The simple way is to start a script with a while/loop+sleep from your running graphical session.
2 - If you insist in using systemd services, than maybe the command "wall" would be handy too (assuming your notification daemon will catch wall messages)
3 - If you absolutely want to use your method, then some additional work is needed.
Take a look at this: https://aur.archlinux.org/packages/batterylife

I strongly suggest 1.
If you need everybody in your system to get the reminder, then i still strongly suggest 2


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#3 2014-11-02 16:17:37

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: systemd timer could not run in X a script with notify-send

You have to tell it where to send the notification to...

Environment=DISPLAY=:0

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#4 2014-11-02 17:45:09

netpumber
Member
Registered: 2009-09-20
Posts: 134

Re: systemd timer could not run in X a script with notify-send

I changed the script to that but doesn't work.

DISPLAY=:0 notify-send -u critical -t 999999999 -c backup "System backup reminder" "It's time to backup the whole system"

Also i add the line

Environment=DISPLAY=:0

in .service file  and still the same.

With

wall notify-send "test" 

i hear just a 'bip' from the machine.

Offline

#5 2014-11-03 12:17:50

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,394

Re: systemd timer could not run in X a script with notify-send

The display envinroment variable itself is not enough to send a notification.
You need to know the dbus session the daemon is registered to as well as the user logged to (which?) display number.
I linked you batterylife package for that reason, it takes care of guessing those informations before sending the notification.
It works for gnome session, but it is adaptable to kde or any DE you're using with some dirty hacking (the scriipt itself is a little hacky).

As for the wall command,
"wall" is a way to send messages to all users logged in, so that:

wall make the backup

will write "make the backup" to every logged users terminal.
Under kde, that message is intercepted by its notification daemon, and a notification pops up saying "make a backup".
I don't know what your de is, so you should check if there is a way to catch those "wall" broadcast messages.

The main question remains...
why do you want to use a service to perform a user/desktop task?
The easy and simple way is to autostart a script as the user logs in...

Last edited by kokoko3k (2014-11-03 12:19:31)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#6 2015-01-06 08:10:23

bittermint
Member
Registered: 2013-07-07
Posts: 6

Re: systemd timer could not run in X a script with notify-send

@kokoko3k and how would you make the command in script to run every x minutes while logged in (X) using the loop + sleep or while and meanhile keep running in the background? (not even me understood what i meant but I hope you do)

Offline

#7 2015-01-07 12:26:22

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,394

Re: systemd timer could not run in X a script with notify-send

@bittermint, it is a bit offtopic, but anyway...
your Desktop environment will probably executes an autostart script file.
Then it is only a matter of compiling it with something like:
My autostart script:

#!/bin/bash
something
something other
MyBackgroundProcess.sh &
...
something

Any MyBackgroundProcess.sh would be like this:

while true ; do
  MyPeriodicProcess
  sleep 60
done

Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

Board footer

Powered by FluxBB