0

I want to make some notification to user every day at the same time:

any_hour:50

And I wrote to crontab -e:

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

When I run it from console:

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

I have desired result:

enter image description here

But when I working at PC I don't have this output at desired time.

Any suggestion?

UPDATE:

I updated cron job to:

50 * * * * DISPLAY=:0 /usr/bin/notify-send -i /home/nazar/Pictures/icons/download_manager.png "Work Break" "Make a break for 10 min, please!" 2>&1 | tee -a cron.out

After executing it file was created but it is empty.

I tried to update my cron job as follows:

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

# just cron test
*/1  *  * * *  /home/nazar/Documents/scripts/cron_job_test.sh

and cron_job_test.sh looks:

#!/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 "hello"

when I run this script from terminal:

./cron_job_test.sh

I get notification correctly.
But crontab doesn't run this script every minute.

Why does this happen?
And how to resolve execution of this cron job?

catch23
  • 221
  • 1
    This is probably because setting DISPLAY isn't enough; your X server must be rejecting the connection. Are you able to receive error output from cron jobs (it sends e-mail)? That would allow use to better understand what is going on. Otherwise, append 2>&1 | tee -a cron.out to your job to create a log file. – dhag Dec 04 '15 at 16:53
  • @dhag can you explain more about logging cron? have should look my updated cron job? – catch23 Dec 04 '15 at 17:16
  • As I said, add 2>&1 | tee -a cron.out to the end of your cron job, and, after it runs, look in file cron.out. – dhag Dec 04 '15 at 18:02
  • @dhag I updated question. – catch23 Dec 04 '15 at 19:54
  • The cron_job_test.sh you pasted is missing the closing " (last line). Is this just a copy & paste error? (Please [edit] your question and fix it if so.) – derobert Dec 04 '15 at 21:14
  • @derobert it is just copy/paste trouble. script works fine. – catch23 Dec 04 '15 at 22:20

1 Answers1

1

You probably need to edit the crontab of that particular user i.e.

su -l nazar
crontab -e
  • can you explain more? I didn't get what your answer means. – catch23 Dec 04 '15 at 16:43
  • 2
    That would only be useful if we had reason to believe the asker is running commands as root, which seems to me an unreasonable assumption. – dhag Dec 04 '15 at 16:46
  • @dhag Do you mean to run sudo crontab -e? – catch23 Dec 04 '15 at 16:47
  • 1
    No, I mean that this answer seems completely irrelevant to your problem. – dhag Dec 04 '15 at 16:50
  • Well he refers to "the user", unless he is referring to himself in the third person it's perfectly logical to assume that he might be trying to edit his own crontab given that he makes no mention of running it under a another user. But thinking about it, shouldn't his above syntax be: 50 * * * * export DISPLAY=:0 && /usr/bin/notify-send -i /home/nazar/Pictures/icons/download_manager.png "Break" "Make a break for 10 min" – user3861788 Dec 04 '15 at 16:58
  • @dcrdev do you mean add &&? – catch23 Dec 04 '15 at 17:13
  • I see where your assumption comes from, @dcrdev, that makes some sense. The VAR=value command form should be valid syntax. – dhag Dec 04 '15 at 18:01