Running from the Console [SOLVED]


#1

Hi all,
I’m currently looking to run a report via Cron to automatically look through records and send alert emails out to users based on certain conditions.

The Console command works fine but when I run from the command line I get

PHP Notice: Undefined variable: argv in /home/airleagu/deploys/admin_develop/Console/cake.php on line 46
Error: This file has been loaded incorrectly and cannot continue.
Please make sure that /lib/Cake/Console is in your system path,
and check the cookbook for the correct usage of this command.
(https://book.cakephp.org/)
#0 /home/airleagu/deploys/admin_develop/Cake/lib/Cake/Console/ShellDispatcher.php(54): ShellDispatcher->_initEnvironment()
#1 /home/airleagu/deploys/admin_develop/Cake/lib/Cake/Console/ShellDispatcher.php(65): ShellDispatcher->__construct(NULL)
#2 /home/airleagu/deploys/admin_develop/Console/cake.php(46): ShellDispatcher::run(NULL)
#3 {main}

I’ve done some research and seen that I need “register_argc_argv” on, however I’m also led to believe that this flag is a bad security practise.

Looking for feedback / advice

Regards,
Brian


#2

BTW - command I’m running from CRON is

cd /home/airleagu/deploys/admin_develop && Console/cake reminder_wwcc

#3

what cake version is this?

And it would be easier if we can see your code


#4

Hi,

Its 2.10.10, code is below. Basically its an app that manages volunteers for a youth group. We need to remind people when their Australian govt. mandated background check for working with children expires to get it renewed.

It grabs an array of members and iterates through the list sending an email. On my local machine it works fine from the command line, but on the hosted server (virtual host) we get the error shown above.

Note - haven’t tried it on the local machine as a CRON JOB - will do that shortly

<?php
App::uses('CakeEmail', 'Network/Email');

/* 
 * Console Command - Used to Mail Out WWCC renewals
 */

class ReminderWwccShell extends AppShell {
	
    // Uses the MemberUnits Model
	
    public $uses = array('MemberUnit');
	
    public function main() {
	    
    // Find all Members with Outstanding or soon to expire WWCC 
	// Hardcoded to Federal (Unit ID 1)
	    
        $wwccList = $this->MemberUnit->haveExpiredWWCC('1');

        if (empty($wwccList) == false) {

		foreach ($wwccList as $member) {
			
			$email = $member['Member']['primary_email'];
			
			if (empty($email) == false AND strlen($email)>1) {
				// Finally send the email...
				$Email = new CakeEmail();
				$Email->config('smtp');
				$Email->emailFormat('html');
				$Email->viewVars(compact('member'));
				$Email->from(['noreply@example.org' => 'AAL Online Admin']);
				$Email->to($email);
				$Email->subject('Working With Children Check Reminder: ' . $member['Member']['membership_number'].' - ' . $member['Member']['first_name'].' ' . $member['Member']['last_name']);
				$Email->template('expiredWwcc', null);
			
				$Email->send();				
			}
			
		}
        }	    
	    
    }
}

#5

I’ve spoken to my hosts who have provided ssh access to the server

I’ve successfully run the commands from the command line, and I’ve also confirmed that the PHP version (command line) is 7.1.19 and register_argc_argv is on.

I’ve also added lib/Cake/Console to the System Path.

I’m starting to run out of ideas.


#6

Ok problem solved.

Different version of PHP running from command line to that used on the web environment.

Changing the file “Cake” from

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

To

exec /opt/alt/php71/usr/bin/php -q “$CONSOLE”/cake.php -working “APP" "@”

Did it.

Regards
Brian