0

This question already has an answer here:

I'm trying to create my first cron job. I'm new to bash scripting too, although I do know some python. I am puzzled by the following:

Here is my cronjob file created with crontab -e:

*/1 * * * * /home/darren/.bash_scripts/urxvt_colors.sh

Contents of urxvt_colors.sh:

#!/bin/bash

python  ~/.Py_Scripts/xr_random_colors.py
xrdb ~/.Xresources

Here is what baffles me. So the python part of the cron job works python ~/.Py_Scripts/xr_random_colors.py is executed every minute. This python script changes the color scheme in my ~/.Xresources file. I confirmed this actually happens by checking every minute. But xrdb ~/.Xresources does not update the file.

Running which python shows /usr/bin/python and which xrdb shows /usr/bin/xrdb. So since they are both executed from /usr/bin, how come only the python script executes?

Also if I run ./urxvt_colors.sh script manually from my terminal then it works as expected, the python script runs and so does xrdb ~/.Xresources

What's happening here?

marked as duplicate by derobert, Stephen Rauch, Kusalananda, Jeff Schaller, Rui F Ribeiro Jun 22 '17 at 20:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Try to change your script like this

#!/bin/bash

python  ~/.Py_Scripts/xr_random_colors.py && xrdb ~/.Xresources

and i recommend you to use full path to files.

PS maybe you need to define DISPLAY var while exec script

*/1 * * * * DISPLAY=:0 /home/darren/.bash_scripts/urxvt_colors.sh
  • Thanks. Adding DISPLAY=:0 to the cronjob got things working. Reading the "This question already has an answer" link above explained to me why :) – Darren Haynes Jun 22 '17 at 22:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.