I have a script web.py which I am trying to run on the aws EC2 Instance using cron. It basically has these line of codes:

import webbrowser

If I run this script through putty using "python web.py" it does hit the browser. But same is not working if I run it via cron. My cron code is :

*/10 * * * * /usr/bin/python  /home/web.py

The way I know its not working is there are few process which get executed once the url is hit. I can see those changes when I run the script through putty but not when I run it through cron.

I tried below modifications also but its not working.

*/10 * * * * export DISPLAY=:0 && /usr/bin/python /home/web.py
*/10 * * * * DISPLAY=:0 /usr/bin/python /home/web.py

Also on echo $DISPLAY I get a null result. Any help would be appreciated.

  • code running from cron knows nothing about your logged-in GUI desktop session (sorry, my vocabulary just crashed: what's the word for that?) -- the python interpreter launched from cron cannot talk to your browser. – glenn jackman May 16 '16 at 17:31
  • Just a shot in the dark here, because it looks like you've got the basics covered with */10 * * * * DISPLAY=:0 /usr/bin/python /home/web.py. Could it be that yr "import webbrowser" in web.py does not correctly identify yr browser when run from cron.... ? – Cbhihe May 17 '16 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.