0

This is part of troubleshooting why my Cron job set up via CPanel to run a Cakephp shell, isn't working.

This is what I initially did, after reading http://book.cakephp.org/2.0/en/console-and-shells.html I created via CPanel cronjob that runs every 1 minute the following command:

php /home4/theadvop/public_html/app/Console/Cake test

By right I'm expecting it to execute TestShell.php (stored in Console/Command). This TestShell.php is a class that extends Appshell, and has a main() function that sends a test email in php code.

All of the above didn't work, no emails were sent, and no error logs were produced anywhere. So i decided to manually test things via SSH as shown below, which also strangely, shows no output.

Via SSH I've browsed to my app directory and tried running Console/cake, I get permission error. So I did a chmod as shown in the attachment. enter image description here

Now I tried running Console/cake from the app folder. But no output and nothing happens. Eventually I have to Ctrl-C my way out of it. enter image description here

I then try to run Console/cake using my php file as a parameter (my php file is called TestShell.php in the Console/Command folder. Again nothing happens. enter image description here

Any idea whats wrong with my setup?

Edited below to include email output.

Note I have changed my Console/Command/TestShell.php to output a line simply like this. It no longer attempts to send an email (to keep things simple)

echo "This is an output from testshell";

My Cron Job when running this:

php /home4/theadvop/public_html/app/Console/Cake test

Will result in the Cron sending me email that looks like this:

Content-type: text/html

################################################################################
#
# Bake is a shell script for running CakePHP bake script
#
# CakePHP(tm) :  Rapid Development Framework (http://cakephp.org)
# Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
#
# Licensed under The MIT License
# For full copyright and license information, please see the LICENSE.txt
# Redistributions of files must retain the above copyright notice.
#
# @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
# @link          http://cakephp.org CakePHP(tm) Project
# @package       app.Console
# @since         CakePHP(tm) v 1.2.0.5012
# @license       http://www.opensource.org/licenses/mit-license.php MIT License
#
################################################################################

# Canonicalize by following every symlink of the given name recursively
canonicalize() {
        NAME="$1"
        if [ -f "$NAME" ]
        then
                DIR=$(dirname -- "$NAME")
                NAME=$(cd -P "$DIR" && pwd -P)/$(basename -- "$NAME")
        fi
        while [ -h "$NAME" ]; do
                DIR=$(dirname -- "$NAME")
                SYM=$(readlink "$NAME")
                NAME=$(cd "$DIR" && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
        done
        echo "$NAME"
}

CONSOLE=$(dirname -- "$(canonicalize "$0")")
APP=$(dirname "$CONSOLE")

exec php -q "$CONSOLE"/cake.php -working "$APP" "$@"
exit

Did not understand the above but i think Cron was executing the wrong thing because the output seemed to be about "baking".

After that I tried to remove the "php" of the cron job command so the cron runs this:

/home4/theadvop/public_html/app/Console/Cake test

The Cron then sends me the following email:

/home4/theadvop/public_html/app/Console/cake: fork: retry: Resource temporarily unavailable
/home4/theadvop/public_html/app/Console/cake: fork: retry: Resource temporarily unavailable
/home4/theadvop/public_html/app/Console/cake: fork: retry: Resource temporarily unavailable
/home4/theadvop/public_html/app/Console/cake: fork: retry: Resource temporarily unavailable
/home4/theadvop/public_html/app/Console/cake: fork: Resource temporarily unavailable
No input file specified.

I still have no idea what i'm doing wrong.

Oldskool
  • 34,211
  • 7
  • 53
  • 66
aDvo
  • 894
  • 4
  • 15
  • 43

3 Answers3

0

Try this method for setting cron in cakephp

Write your code in a controller's action. Then check for cron_dispatcher.php in webroot folder. In there is no such file download it from internet. Google for it you will find easily. Or check this link Cron Dispatcher CakePHP 2.0 And then set below path in cpanel :-

  php /home4/theadvop/public_html/app/webroot/cron_dispatcher.php /controller/action

Remind that put a die() in the end of your code otherwise it will give error for a ctp file. Or put a blank ctp file for that function.

Hope it will help

Community
  • 1
  • 1
  • hi, unless ill try your method only if i really run out of possible solutions for doing it the proper cake way. From what i understand there shuldn't be a need to use the dispatcher for this – aDvo Jun 06 '14 at 06:40
  • replace php with cd in your cronjob command. Check http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html – Bharat Maheshwari Jun 06 '14 at 06:55
0

create a file in webroot folder of cake php. The file contains all the cron url with their timings like this :-

 * 10 * * * /usr/bin/curl http://cronurl/

Now execute this command

 crontab /path/to/file

your cron job will be added. You can also list all cron jobs under every user through the following command.

for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done
Harish Lalwani
  • 754
  • 5
  • 20
0

Add extention .php after /cake

php bin/cake.php server...
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123