1

Okay so I have a bash script that simply downloads a web page, and then I use python to pulls some data out of the downloaded page. So my bash script is along the lines of

#!/bin/bash
html_file="web_page.html"
wget -O /home/michael/Documents/CS288/homework7/web_page.html http://markets.usatoday.com/custom/usatoday-com/html-mktscreener.asp?exchange=13\&screen=1
python hw_7_2.py $html_file

Now, when I just execute this bash script from the command line it runs fine, the wget runs and then my python script executes, however when I set it up as a cron job the wget will run but the python script never executes. I have not really set up cron jobs so this I think may be the issue. This is basically what my crontab file looks like

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 * * * * * michael /home/michael/Documents/CS288/homework7/usatoday_runner.sh
Cœur
  • 37,241
  • 25
  • 195
  • 267
mike
  • 3,339
  • 6
  • 30
  • 34
  • 1
    Though not apparently the problem, setting `$html_file` and then not using it for the output of `wget` is an excellent way to cause yourself problems down the line. – blahdiblah Apr 29 '11 at 16:42
  • if you use Debian, don't forget to take care about the cronjob's filename, as described [here](http://stackoverflow.com/questions/5486601/linux-debian-crontab-job-not-executed). – hornetbzz May 01 '11 at 19:01

3 Answers3

2

try to replace the cron line with :

* * * * * michael /home/michael/Documents/CS288/homework7/usatoday_runner.sh > /tmp/why_is_this_failing.log 2>&1

the answer may be in the /tmp/why_is_this_failing.log

Cédric Julien
  • 78,516
  • 15
  • 127
  • 132
  • Thanks Cedric, the error log helped, like some others stated I just want in the correct directory when the python script tried to execute – mike Apr 29 '11 at 16:52
1

It's possible that your script doesn't have some environment variables set. When a cron job runs it doesn't have your normal profile information - it doesn't load your .profile/.bashprofile (simpler path, JAVA_HOME, etc) one possible option is to have the script source your .profile etc.

BZ.
  • 1,928
  • 2
  • 17
  • 26
1

Cron frequently fails because of $PATH/working directory sorts of problems. You're setting the $PATH, but I wouldn't be surprised if neither your bash script nor your python script work if you aren't in the right directory.

Try using more absolute paths and see if that clears things up. Similarly, try running your cron command yourself from / or someplace and see if it works for you.

blahdiblah
  • 33,069
  • 21
  • 98
  • 152