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:
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!"
Best Answer
You need to set
XDG_RUNTIME_DIR
as well. Change your crontab to this:Make sure you change
nazar
to whatever your username is and1001
to your actual UID. You can get your UID by runningid -u
.And all you need in your script is:
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.