title: Creating Cron Jobs in CakePHP 2.x
body: <p>I have attempted to create a cron job in my CakePHP 2.x application. But all of the resources I have read online seem to be either doing it completely different to one another with little consistency or explain it in very complex terminology.</p>
  
  <p>Basically I have created the following file <code>MyShell.php</code> in <code>/app/Console/Command</code></p>
  
  <pre><code>&lt;?php 
  
  class MyShell extends Shell {
  
      public function sendEmail() {
  
          App::uses('CakeEmail', 'Network/Email');
  
          $email = new CakeEmail();
  
          $email-&gt;from('cameron@driz.co.uk');
  
          $email-&gt;to('cameron@driz.co.uk');
  
          $email-&gt;subject('Test Email from Cron');
  
          $result = $email-&gt;send('Hello from Cron');
  
      }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>And I want to say run this code at midnight every night.</p>
  
  <p>What do I do next? As the next part really confuses me! I have read on the Book at: <a href="http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html" rel="nofollow">http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html</a> that I should run some code in the terminal to make it do it at a certain time etc. And I can set these up using my hosting provider rather easily it seems.</p>
  
  <p>But I'm rather confused about the Console directory. What should go in what folder in here: <a href="https://github.com/cakephp/cakephp/tree/master/app/Console" rel="nofollow">https://github.com/cakephp/cakephp/tree/master/app/Console</a></p>
  
  <pre><code>/Console/Command
  /Console/Command/Tasks
  /Console/Templates
  </code></pre>
  
  <p>Also noticed that many of the files are .php (e.g. my Shell file is also .php), but according to documentation I've read for Cron jobs, the executed files should be .sh?</p>
  
  <p>Can anyone shed more light on this?</p>
  
  <p>And what would the code be to call that command?</p>
  
  <p>e.g. would presume this is incorrect: <code>0 0 * * * cd /domains/driz.co.uk/html/App &amp;&amp; cake/Console MyShell sendEmail</code></p>
  
  <p>Thanks</p>