So I need to set up a scheduled task in silverstripe 2.4.5.
I read through the documentation and extended DailyTask / HourlyTask etc - all fine.
Called cli-script.php HourlyTask via ssh - worked fine.
Set up a cron job with the command line as:
php /path/to/site/sapphire/cli-script.php HourlyTask > /path/to/site/logs/logfile.log
The command gets run and a log file is created only the contents of the log are this:
Status: 302 OK
Content-Type: text/html; charset="utf-8"
Visiting the site at http://my.site.com/HourlyTask prompts for admin login - which is to be expected apparently.
So I am having some user permissions problem I'm guessing. Looks like root via the cli doesn't need to log in to silverstripe to run the commands, but http and cron, which I guess runs as nobody do...
So How do I authenticate or bypass authentication.
I looked through these threads:
I have created an _ss_environment.php file with the $_FILE_TO_URL_MAPPING set and put this in my base directory - it made no difference
I have tried using bash / sh / sake instead of php / cli-script.php - still the same problem
I have tried using su to execute the command as a different user which works via the command line but fails to even produce a log file when done through cron. eg.
su username -c '/bin/sh /path/to/my/site/sapphire/sake HourlyTask > /path/to/my/site/silverstripe-logs/silverstripe_hourlytask.log'
Any other ideas??