1

I wrote a bash script to display the current xkcd comic in my web browser (using the RXKCD package in R). I want to schedule this so that the current xkcd comic displays every morning at 8am when I get into work. However, crontab doesn't seem to want to cooperate with me. I've found lots of material online where crontab fails, but still can't seem to figure out what's wrong with my situation.

Here is the bash script:

#! /bin/bash
R CMD BATCH todaysXKCD.R

and here is 'todaysXKCD.R'

library(RXKCD)
getXKCD(html=T, display=F)

I've set up a crontab using crontab -e, and that looks like this:

SHELL=/bin/bash
PATH=/home/pfrater/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
* * * * * root /bin/bash /home/pfrater/bashScripts/xkcd/todaysXKCD.sh

The script works perfectly when I call it from the command line, but not at all with cron. What am I doing wrong? Do I need to add the path for my bashscript to the PATH in the crontab?

Paul
  • 233
  • 3
  • 9
  • Possible duplicate of [How to start a GUI application from cron?](http://askubuntu.com/questions/514167/how-to-start-a-gui-application-from-cron) – muru Apr 07 '16 at 15:33
  • If it opens the browser, you need to have `DISPLAY` set. – muru Apr 07 '16 at 15:34
  • Thanks, muru. I think this is it. When I set the crontab file to `* * * * * DISPLAY=:0 firefox /home/pfrater/bashScripts/xkcd/todaysXKCD.sh` it now opens firefox, but just shows the script file as plain text in firefox. I'll have to play around with it to get it to work. – Paul Apr 07 '16 at 15:40
  • 1
    Okay, perfect. Instead of using the script I just put `0 8 * * 1-5 DISPLAY:0 firefox xkcd.com`. Works great. Thanks. – Paul Apr 07 '16 at 15:43
  • How about a `DISPLAY=:0 /home/pfrater/bashScripts/xkcd/todaysXKCD.sh`? – muru Apr 07 '16 at 15:44
  • That does not seem to work. Only when I just use the display to call the website directly. – Paul Apr 15 '16 at 10:23
  • @PaulFrater try placing the variable into your script – Sergiy Kolodyazhnyy Apr 15 '16 at 22:48

0 Answers0