views:

674

answers:

3

Hi All,

I'm trying to create a cron job that will send a weekly newsletter. I tried creating a shell task following what Cakephp manual says. Then I go to the Media Temple Cron jobs and type in the following:

php /home/#####/domains/domain.com/html/cake/console/cake -app /home//#####//domains/domain.com/html/vendors/shells newsletter

I created the shell task on vendors/shell folder and named it newsletter.php and here's the code for it:

class NewsletterShell extends Shell {

    function main() {

 $this->sendEmailTo("Newsletter","subject","[email protected]");


    }
}

The sendEmailTo is a controller function I have in my appController so all my controller have access to it.

My problem is every time the Cron Job runs I get this message:

Could not open input file: /home/#####/domains/domain.com/html/cake/console/cake

I even gave all the console files (cake.php , cake.bat etc) 0777 read write properties as well as for the vendors/shell/newsletter.php

The ##### are the site number that media temple gives you but I'm not really sure I have it correct. They show an example of a cron job like this: /home/50838/data/script-name.sh

So my questions are:

Is my cake shell task correct and is the way I'm running it as a cron job accurate?

Also does anyone know where to confirm my media temple site number so I can write that off as a possible error.

Thanks in advance,

Fabian

A: 

You can try to var_dump(ROOT) or any one of the other Core Definition Constants to find your directory. Just put it in a controller method somewhere, but make sure to remove it again. Or, if you have SSH access, do pwd on the command line.

Other than that, when invoking the cake console task, the -app parameter is supposed to point to the app directory, not the shells directory.


Try to use this script to run your shell as cron job, there may be some missing shell vars.

deceze
vad_dump(Root) worked great, I tried it and got the real site number and did the new with ls- ld /home/#####/ and it gave me this:drwxr-xr-x 9 root domain.com 9 Sep 12 05:13 /home/#####/and for ls -l /home/#####/domains/domain.com/html/cake/console/cake-rwxrwxrwx 1 domain.com domain.com 987 Oct 29 01:13 /home/#####/domains/domain.com/html/cake/console/cake
Fabian Brenes
Ok now the cron job seems to work but it's not running what's on the main function. Here's the output I'm receiving. http://bin.cakephp.org/view/904014056
Fabian Brenes
I get the same response even If I change the cronjob I've tried:php /home/#####/domains/domain.com/html/cake/console/cake newsletterphp /home/#####/domains/domain.com/html/cake/console/cake newsletter top10 top10 is a diferente function in the newsletter.php shell. They all give the same response: bin.cakephp.org/view/904014056
Fabian Brenes
See update, I've always had success using that technique so far.
deceze
Media temple won't allow me to create a cronjob that looks like that. I tried: php /home/####/domains/domain.com/html/vendors/cakeshell newsletter top10 -console /home/####/domains/domain.com/html/cake/console/cake -app /home/####/domains/modelhousethefilm.com/html/
Fabian Brenes
Also Tried: php /home/####/domains/domain.com/html/vendors/cakeshell newsletter top10 -cli /usr/bin -console /home/####/domains/domain.com/html/cake/console -app /home/#####/domains/domain.com/html/
Fabian Brenes
A: 
ls -l /home/#####/domains/domain.com/html/cake/console/cake

says what? does the cron job run as user #####? if not, the problem is probably permissions on /home/#####/, check them with

ls -ld /home/#####/
just somebody
ls: /home/#####/: No such file or directoryls: /home/####/domains/domain.com/html/cake/console/cake: No such file or directorySo I guess my site number is wrong.
Fabian Brenes
A: 

Have you given the "cake" file in "cake/console" directory executable permissions as well as cake.php and cake.bat?

The cron command should be:

php /home/#####/domains/domain.com/html/cake/console/cake newsletter -app /home/#####/domains/domain.com/html/app

neilcrookes
Yup already gave them executable rights, the problem was with the site number and how I was calling the cron job as you clearly pointed out.
Fabian Brenes