4

I am using Linux Mint 17.
I want to be informed every 50 min, at every hour for small break.

Here is cron job:

nazar@desktop ~ $ crontab -l

DISPLAY=:0.0 XAUTHORITY=/home/matrix/.Xauthority

00 13 * * * /home/nazar/Documents/scripts/lunch_break_job.sh # JOB_ID_2 50 * * * * /home/nazar/Documents/scripts/pc_break.sh # JOB_ID_1

          • /home/nazar/Documents/scripts/cron_job_test.sh # JOB_ID

Here is script for /home/nazar/Documents/scripts/cron_job_test.sh:

#!/bin/bash

export DISPLAY=0.0 export XAUTHORITY=/home/matrix/.Xauthority

if [ -r "$HOME/.dbus/Xdbus" ]; then . "$HOME/.dbus/Xdbus" fi

/usr/bin/notify-send -i "hello"

This snippet of function:

if [ -r "$HOME/.dbus/Xdbus" ]; then
  . "$HOME/.dbus/Xdbus"
fi

Checks DBUS_SESSION_BUS_ADDRESS and uses it.

According to this answer I executed script, and now my Dbus is saved to $HOME/.dbus/Xdbus:

nazar@desktop ~ $ cat $HOME/.dbus/Xdbus
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-flm7sXd0I4,guid=df48c9c8d751d2785c5b31875661ebae
export DBUS_SESSION_BUS_ADDRESS

All should work. I couldn't find what is missed. Because notification doesn't work now.

From terminal it works fine:

enter image description here

How to solve this issue?

SOLUTION:

Now my crontab looks as follows:

DISPLAY=":0.0"
XAUTHORITY="/home/nazar/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1000"
00 13 * * * /home/nazar/Documents/scripts/lunch_break_job.sh # JOB_ID_2
50 * * * * /home/nazar/Documents/scripts/pc_break.sh # JOB_ID_1
# * * * * * /home/nazar/Documents/scripts/cron_job_test.sh # JOB_ID

and cron_job_test.sh looks now:

#!/bin/bash

/usr/bin/notify-send -i /home/nazar/Pictures/icons/Mail.png "hello" "It is just cron test message"

pc_break.sh:

#!/bin/bash

/usr/bin/notify-send -i /home/nazar/Pictures/icons/download_manager.png "Break:" "Make a break for 10 min"

lunch_break_job.sh:

#!/bin/bash

/usr/bin/notify-send -i /home/nazar/Pictures/icons/Apple.png "Lunch: " "Please, take a lunch!"

catch23
  • 221
  • actually the script is not correctly working is the one should notify every 50 min right? but you didn't showed to us the /home/nazar/Documents/scripts/pc_break.sh script. Maybe there is an error in there ? – lese Dec 07 '15 at 09:32
  • Have you tried to run the script in crontab as your user nazar? 50 * * * * nazar /home/nazar/Documents/scripts/pc_break.sh # JOB_ID_1 – syss Dec 07 '15 at 09:33
  • @lese I want clarify that I post firstly my problem and show some test example. pc_break job and script are correct. And this job cron_job_test.sh is just test to verify if cron works, in general. – catch23 Dec 07 '15 at 09:36
  • @syss After your comment I have already tried. And this doesn't work. Job looks correct to cron job wiki info. – catch23 Dec 07 '15 at 09:39

1 Answers1

5

You need to set XDG_RUNTIME_DIR as well. Change your crontab to this:

DISPLAY=":0.0"
XAUTHORITY="/home/nazar/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1001"
00 13 * * * /home/nazar/Documents/scripts/lunch_break_job.sh # JOB_ID_2
50 * * * * /home/nazar/Documents/scripts/pc_break.sh # JOB_ID_1
* * * * * /home/nazar/Documents/scripts/cron_job_test.sh # JOB_ID

Make sure you change nazar to whatever your username is and 1001 to your actual UID. You can get your UID by running id -u.

And all you need in your script is:

#!/bin/bash

/usr/bin/notify-send "hello" 

I just tested this on Arch running Cinnamon and it worked fine.

The variables are being set in the crontab, no need to export anything from the script. There's also no point in doing so, the script is being called by cron, it wouldn't export the values you need anyway.

terdon
  • 242,166