I'm using external cron with apache and I've been able to get a simple
python script to run by calling it directly using

*/1 * * * * root cd /home/www-data/web2py/applications/appname/private/
scripts && python scriptname.py -J -C -D 1 >> /tmp/cron.output 2>&1

The debugging output also was working.

Now what I want to do is call a web2py controller function using
external cron.

First I tried

*/1 * * * * root cd /home/www-data/web2py/applications/appname/private/
scripts && python scriptname.py -M -J -C -D 1 >> /tmp/cron.output 2>&1

This ran the script but I got an error with my logger that said that
db was not defined.  My script needs to use the Database.

I saw that -M needs to be used with -S so I added that to my cron
line.

*/1 * * * * root cd /home/www-data/web2py/applications/appname/private/
scripts && python scriptname.py -S appname -M -J -C -D 1 >> /tmp/
cron.output 2>&1

That still left me with a "db is not defined" error.


So now I'm thinking perhaps you are supposed to put

*/1 * * * * web2py cd /var/www/web2py/ && python web2py.py -J -C -D 1
>> /tmp/cron.output 2>&1

in your external crontab file and then use web2py's application
crontab file to run a controller function so I added

*/1 * * * * root *autoemail/send_autoemails

to my application crontab and let it run.

In my external cron logs I saw that web2py did indeed start up but my
script may or may not have run.  The desired DB result didn't happen.


Two questions:

1.) Which method is correct and what am I doing wrong?
2.) How do I log errors from a cron line that looks like this: */1 * *
* * root *autoemail/send_autoemails so I can see if at least my
controller function ran?



Reply via email to