Run crontab using "notify"

3

I explain the problem a bit above, but basically that's it. I want to add a script in crontab that runs every minute. The script, on the other hand, should show a simple greeting message. He has no more.

Chrontab line:

* * * * * sh /tmp/notify-test.sh

As I understand it, that would execute my "sh" every minute, right?

On the other hand, this is the script:

#!/bin/bash

/usr/bin/notify-send "Hola" "¿Qué tal?"

The notify-send command works correctly in Terminal. I added the path /usr/bin/ because I had read that I had to enter the complete path of the command. Using the whereis I found that route.

After the supposed minute, the syslog of Ubuntu shows me CMD (sh /tmp/notify-test.sh) , ergo I deduce that it executes correctly. Is the problem in the content?

Greetings!

    
asked by Viral 17.05.2016 в 13:04
source

1 answer

2

This should work for you (it worked for me, I saw it on Unix & Linux ):

DISPLAY=:0.0
XAUTHORITY=/home/<tu_usuario>/.Xauthority
#               ^^^^^^^^^^^^^
#               modifica esto
* * * * * /usr/bin/notify-send "hola"

Also note that you are saying:

* * * * * sh /tmp/notify-test.sh

What this does is run the script with sh , instead of the bash that you surely want. Therefore, you should modify it to one of these:

  • Indicate in the cronjob:

    * * * * * /bin/bash /tmp/notify-test.sh
    
  • Make the file executable ( chmod +x notify-test.sh ) so that it recognizes the binary with which to execute it from the shebang:

    * * * * * /tmp/notify-test.sh
    
answered by 17.05.2016 / 13:18
source