# Running from the Console \[SOLVED\]

**URL:** <https://discourse.cakephp.org/t/running-from-the-console-solved/4546>\
**Category:** Need Help\
**Created:** [July 10, 2018, 10:57pm UTC](https://discourse.cakephp.org/t/running-from-the-console-solved/4546 "2018-07-10T22:57:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgrinter](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bgrinter/32/1381_2.png) [@bgrinter](https://discourse.cakephp.org/u/bgrinter)\
**Post date:** [July 10, 2018, 10:57pm UTC](https://discourse.cakephp.org/t/running-from-the-console-solved/4546/1 "2018-07-10T22:57:34Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![bgrinter](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bgrinter/32/1381_2.png) [@bgrinter](https://discourse.cakephp.org/u/bgrinter)\
**Post date:** [July 11, 2018, 9:43am UTC](https://discourse.cakephp.org/t/running-from-the-console-solved/4546/2 "2018-07-11T09:43:40Z")

</div>

BTW - command I’m running from CRON is

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

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [July 11, 2018, 10:02am UTC](https://discourse.cakephp.org/t/running-from-the-console-solved/4546/3 "2018-07-11T10:02:46Z")

</div>

what cake version is this?

And it would be easier if we can see your code

---

<div class="post-metadata">

**Author:** ![bgrinter](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bgrinter/32/1381_2.png) [@bgrinter](https://discourse.cakephp.org/u/bgrinter)\
**Post date:** [July 11, 2018, 8:47pm UTC](https://discourse.cakephp.org/t/running-from-the-console-solved/4546/4 "2018-07-11T20:47:10Z")

</div>

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();				
			}
			
		}
        }	    
	    
    }
}
```

---

<div class="post-metadata">

**Author:** ![bgrinter](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bgrinter/32/1381_2.png) [@bgrinter](https://discourse.cakephp.org/u/bgrinter)\
**Post date:** [July 12, 2018, 1:14pm UTC](https://discourse.cakephp.org/t/running-from-the-console-solved/4546/5 "2018-07-12T13:14:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bgrinter](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bgrinter/32/1381_2.png) [@bgrinter](https://discourse.cakephp.org/u/bgrinter)\
**Post date:** [July 14, 2018, 6:21am UTC](https://discourse.cakephp.org/t/running-from-the-console-solved/4546/6 "2018-07-14T06:21:51Z")

</div>

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
