0

I'm trying to setup a cron job to run a console command every minute.

class RescanCommand extends Command {

public function sendMail() {
    $email = new Email();

    // Sample SMTP configuration.
    Email::setConfigTransport('mailtrap', [
        'host' => 'smtp.mailtrap.io',
        'port' => 25,
        'username' => 'username',
        'password' => 'pass',
        'className' => 'Smtp'
    ]);

    $email->setFrom(['test@test.com' => 'CSV file'])
        ->setTo('test@test.com')
        ->setSubject('CSV Link File')
        ->send('Please find attached a copy of the links');
}

public function execute(Arguments $args, ConsoleIo $io) {
    $this->sendMail();
}
}

I can run the above code from command line by

bin/cake rescan execute

and I receive the test email, but after creating a cron job by editing cron tabs like

crontab -e

and inside the file by writing

*/1 * * * * cd /Applications/MAMP/htdocs/music && bin/cake Rescan execute

nothing happens, I was expecting to receive emails every minute,

can anyone please help find out what I'm doing wrong.

Thanks

akano1
  • 40,596
  • 19
  • 54
  • 67
  • first look at cli-errors log, cd corect path to app folder and && bin/cake Rescan execute where rescan need to be lowercase. – Salines Sep 13 '18 at 11:37
  • @Salines there's nothing in the cli-errors log, I checked the path and it's correct and change the Rescan to lowercase, but still not receiving anything. – akano1 Sep 13 '18 at 11:46
  • @Salines I'm using Cakephp built in server, does the crontab -e make the cronjob to run at the built in server? – akano1 Sep 13 '18 at 11:47
  • "The software utility cron is a time-based job scheduler in Unix-like computer operating systems." . Your "web server" must contain httpserver , mysql, cron / sheduletask, and other software. CakePHP bulit in server is't http server. Why not try web development with https://www.vagrantup.com/ ? – Salines Sep 13 '18 at 12:21
  • Check this [Cron Jobs on Shared Hosting](https://book.cakephp.org/3.0/en/console-and-shells/cron-jobs.html) – Exterminator Sep 13 '18 at 13:45
  • @amir, if you run "bin/cake rescan execute" means you're already in the app directory, what happens when you run "cd /Applications/MAMP/htdocs/music && bin/cake Rescan execute", does it work? – Yevgeniy Sep 13 '18 at 18:06
  • @Yevgeniy It works, it sends the email as expected. – akano1 Sep 13 '18 at 18:49
  • @amir I had an issue with running cake/bake from post-receive hooks — it turned out that it requires sudo, may be you have a similar issue? I would add echo or log for this task to see if it's running at all. If it runs and logs data, then try adding the script to sudo. I added: user_name ALL=(ALL:ALL) NOPASSWD:/full_path/bin/cake to /etc/sudoers on ubuntu and that solved my issue – Yevgeniy Sep 18 '18 at 05:35

0 Answers0