1

I have a Ruby script with the command

`notify-send "Error in EYW Spaces script" "#{Shellwords.escape(message)}"`

If I just run the script from the command line, I get the popup message, but if I put the script into the crontab

*/5 * * * * ruby ~/software_dev/scripts/new_script.rb

then nothing happens. I know for a fact that the script is running correctly, as I'm getting script output emailed to me, but its just that the popup is not appearing.

Any ideas?

Jamie G
  • 156
  • 1
  • 8
  • 1
    `notify-send` probably isn't in your `PATH` when your script runs from cron. You're better off, in general, not assuming that `PATH` has anything in particular unless your script sets it itself. Maybe your script should use the full path to `notify-send` rather than relying on `PATH`. – mu is too short Mar 18 '19 at 18:07

2 Answers2

1

Looks like this isn't specifically a ruby issue, but its due to calling notify-send from crontab.

https://askubuntu.com/questions/298608/notify-send-doesnt-work-from-crontab

One solution on there was to add DISPLAY=:0 to your script:

`DISPLAY=:0 notify-send "Error in EYW Spaces script" "#{Shellwords.escape(message)}"`
  • Funnily enough, this worked for another command that wasn't working `zenity --info ....`, which now displays when DISPLAY=:0 is set, but notify-send doesn't. Will have a play with the PATH – Jamie G Mar 19 '19 at 11:10
0

Possible issues:

  • The user running the crontab (root, you, ???) and their system permissions
  • ruby version and notify-send in that user's PATH
  • Not specifying the DISPLAY variable in your cron

Try this (change the number to the correct DISPLAY value) -->

*/5 * * * * DISPLAY=:0 ruby ~/software_dev/scripts/new_script.rb

May be helpful: https://unix.stackexchange.com/questions/10121/open-a-window-on-a-remote-x-display-why-cannot-open-display

Greg Ruhl
  • 1,060
  • 2
  • 9
  • 27