3

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@lelyak-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@lelyak-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"
  • 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 7 '15 at 9: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 7 '15 at 9: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. – nazar_art Dec 7 '15 at 9:36
  • @syss After your comment I have already tried. And this doesn't work. Job looks correct to cron job wiki info. – nazar_art Dec 7 '15 at 9:39
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.

  • thanks for such great answer. But it doesn't want work on Linux Mint 17. I couldn't guess why. – nazar_art Dec 7 '15 at 11:06
  • @nazar_art did you use my username or yours? Also, the 1001 should be your UID. You can find out what yours is by running id -u. – terdon Dec 7 '15 at 11:13
  • I had deleted redundant lines from crontab and now it works. – nazar_art Feb 12 '17 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.