0

Every now and then I close the program workrave. E.g. when I am watching a movie. Then I forget restarting it.

So, I want to restart it repeatedly. Somehow cron does not work. Following gives a summary:

ubuntu bionic (18.04)

i am a normal user (not root)

$ xhost
access control enabled, only authorized clients can connect
INET:localhost
INET6:localhost
SI:localuser:USERNAME

$ echo $DISPLAY
:0

$ crontab -l
* * * * * export DISPLAY=:0 && /usr/bin/workrave

when I open a tilix terminal and type /usr/bin/workrave, the program starts fine.

The command

* * * * * env DISPLAY=:0 /usr/bin/workrave

does not work either.

O. Altun
  • 101

1 Answers1

0

Let's assume your user name is tiger - just replace everywhere below the name with your real name of user. Create bash script in the home directory of your user:

touch /home/tiger/workrave.sh

Make the created script executable:

chmod +x /home/tiger/workrave.sh

Open the script in text editor, let it be nano for instance:

nano /home/tiger/workrave.sh

Insert into the script its content (don't forget to replace tiger):

#!/bin/bash
ifrun=$(pgrep -cxu tiger -f /usr/bin/workrave)
if [[ $ifrun == 0 ]] ;
then
    DISPLAY=:0 /usr/bin/workrave &
fi

Save changes and close text editor. Open crontab as tiger:

crontab -e

Add to end of crontab the line (don't forget to replace tiger):

*/1 * * * * /home/tiger/workrave.sh

Save and close crontab. Check if everything works (cron will run the script every minute). Setup time for the script execution. That's all.

Remark. The script executes workrave only if other its instances aren't running.

UPDATE

Script for testing purposes (replace tiger):

#!/bin/bash
DISPLAY=:0 /usr/bin/workrave 2>> /home/tiger/workrave-errors.log
Bob
  • 2,533
  • Thanks for the code that checks whether workrave is running. The script works when I run it from the terminal. But it does not work through cron. I am using budgie desktop on ubuntu. Each minute I see the workrave icon in its toolbar, but it goes away immediately. (it does not work in unity either) – O. Altun Jul 13 '18 at 09:22
  • I did. But I get the same behavior. – O. Altun Jul 13 '18 at 09:56