Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have read most of the python/cron here in stackoverflow and yet couldn't make my script run.. I understood that I need to run my script through shell (using zsh & ipython by the way). but really I have no idea what to do :/ my simple code: in the crontab-

*/1 * * * * ipython /home/usr/Data/progs/cron_test.py

my python script-

import pickle
    from selenium import webdriver

driver = webdriver.Firefox()
driver.get('http://www.google.com')

t=driver.current_url
pickle.dump(t,open('noreal','wb'))

tried some things already but to no avail:

    #!python ../python etc
    SHELL = /usr/bin/zsh
    PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

simply because i don't know what what is the problem, I assume something with running python script via interpreter, but, of I don't know what I am doing really :) a working solution would be great, and I would really appreciate an explanation to accompany any solution so i could understand the why and how and not just be like 'it work!thanks!bye!'. thanks for any help!

update So far i have narrowed down the problem, and now python runs with the next settings:

*/3 * * * * /usr/local/bin/ipython /home/user/Data/progs/RF/cron_test.py

and got a traceback:

[1;31m---------------------------------------------------------------------------[0m
[1;31mWebDriverException[0m                        Traceback (most recent call last)
[1;32m/usr/local/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc[0m in [0;36mexecfile[1;34m(fname, *where)[0m
[0;32m    176[0m             [1;32melse[0m[1;33m:[0m[1;33m[0m[0m
[0;32m    177[0m                 [0mfilename[0m [1;33m=[0m [0mfname[0m[1;33m[0m[0m
[1;32m--> 178[1;33m             [0m__builtin__[0m[1;33m.[0m[0mexecfile[0m[1;33m([0m[0mfilename[0m[1;33m,[0m [1;33m*[0m[0mwhere[0m[1;33m)[0m[1;33m[0m[0m
[0m
[1;32m/home/user/Data/progs/FB/cron_test.py[0m in [0;36m<module>[1;34m()[0m
[0;32m      9[0m [1;33m[0m[0m
[0;32m     10[0m [1;33m[0m[0m
[1;32m---> 11[1;33m [0mdriver[0m [1;33m=[0m [0mwebdriver[0m[1;33m.[0m[0mFirefox[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m     12[0m [0mdriver[0m[1;33m.[0m[0mget[0m[1;33m([0m[1;34m'http://www.google.com'[0m[1;33m)[0m[1;33m[0m[0m
[0;32m     13[0m [1;33m[0m[0m

[1;32m/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.pyc[0m in [0;36m__init__[1;34m(self, firefox_profile, firefox_binary, timeout, capabilities, proxy)[0m
[0;32m     58[0m         RemoteWebDriver.__init__(self,
[0;32m     59[0m             command_executor=ExtensionConnection("127.0.0.1", self.profile,
[1;32m---> 60[1;33m             self.binary, timeout),
[0m[0;32m     61[0m             desired_capabilities=capabilities)
[0;32m     62[0m         [0mself[0m[1;33m.[0m[0m_is_remote[0m [1;33m=[0m [0mFalse[0m[1;33m[0m[0m

[1;32m/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.pyc[0m in [0;36m__init__[1;34m(self, host, firefox_profile, firefox_binary, timeout)[0m
[0;32m     45[0m         [0mself[0m[1;33m.[0m[0mprofile[0m[1;33m.[0m[0madd_extension[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m
[0;32m     46[0m [1;33m[0m[0m
[1;32m---> 47[1;33m         [0mself[0m[1;33m.[0m[0mbinary[0m[1;33m.[0m[0mlaunch_browser[0m[1;33m([0m[0mself[0m[1;33m.[0m[0mprofile[0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m     48[0m         [0m_URL[0m [1;33m=[0m [1;34m"http://%s:%d/hub"[0m [1;33m%[0m [1;33m([0m[0mHOST[0m[1;33m,[0m [0mPORT[0m[1;33m)[0m[1;33m[0m[0m
[0;32m     49[0m         RemoteConnection.__init__(

[1;32m/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc[0m in [0;36mlaunch_browser[1;34m(self, profile)[0m
[0;32m     59[0m [1;33m[0m[0m
[0;32m     60[0m         [0mself[0m[1;33m.[0m[0m_start_from_profile_path[0m[1;33m([0m[0mself[0m[1;33m.[0m[0mprofile[0m[1;33m.[0m[0mpath[0m[1;33m)[0m[1;33m[0m[0m
[1;32m---> 61[1;33m         [0mself[0m[1;33m.[0m[0m_wait_until_connectable[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m     62[0m [1;33m[0m[0m
[0;32m     63[0m     [1;32mdef[0m [0mkill[0m[1;33m([0m[0mself[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m

[1;32m/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc[0m in [0;36m_wait_until_connectable[1;34m(self)[0m
[0;32m     98[0m                 raise WebDriverException("The browser appears to have exited "
[0;32m     99[0m                       [1;34m"before we could connect. The output was: %s"[0m [1;33m%[0m[1;33m[0m[0m
[1;32m--> 100[1;33m                       self._get_firefox_output())
[0m[0;32m    101[0m             [1;32mif[0m [0mcount[0m [1;33m==[0m [1;36m30[0m[1;33m:[0m[1;33m[0m[0m
[0;32m    102[0m                 [0mself[0m[1;33m.[0m[0mkill[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m

[1;31mWebDriverException[0m: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n' 
share|improve this question
    
What's the benefit of ipython for this epitome of non-interactive use? –  tripleee Dec 13 '13 at 20:59
    
Non i guess, sould it matter for the issue? I don't mind using plain Python –  user2627775 Dec 13 '13 at 21:29
    
What's the significance of the "things you tried already"? None of them are syntactically correct. A correct shebang would be something like #!/usr/bin/env python and the assignments must not contain any whitespace. –  tripleee Dec 14 '13 at 9:23
    
Thanks triplee i've changed the things. Now python works, and i got a traceback. –  user2627775 Dec 14 '13 at 13:11
    
The color codes are really disruptive, could you run it through colcrt to clean it up? –  tripleee Dec 14 '13 at 13:58

2 Answers 2

up vote 2 down vote accepted

A quick guess, your job fails to run because it requires an X session. You should setup your test script to run in a headless mode. Check this link to run selenium in a headless mode.

update:
Your trace says exactly what I meant, firefox does not run without X, or a display if you want.

 The output was: Error: no display specified\n' 

Save yourself more trouble, read the link I posted.

share|improve this answer
    
I moved to something simpler just to check, did pickle.dump for a list into a file, doesn't create the file, so i take it as a proof that it's still not working. –  user2627775 Dec 13 '13 at 21:26
    
did you see an error? does your script break? do other cronjobs work? –  Oz123 Dec 13 '13 at 21:41
    
a simple cronjob work:echo 'hello word' >> /tmp/hello.txt, in the python case i see nothing so i can't traceback the problem.. –  user2627775 Dec 13 '13 at 21:52
    
open('cat_name_charlie_echo', 'wb')), you are opening a file, withou t a path. Try putting it with a full path where your cronuser can read and right and your user too. For example /tmp/cat_name.txt... –  Oz123 Dec 14 '13 at 9:02
    
Without any error message, there isn't much to go on. Does python -v run as you would expect from Cron? –  tripleee Dec 14 '13 at 9:16

As seen here, you need to give cron a display:

30 5 * * * export DISPLAY=:0; /home/me/good_morning.sh
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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