Skip to content

Instantly share code, notes, and snippets.

@jhowbhz
Last active August 31, 2023 14:41
Show Gist options
  • Save jhowbhz/51efa7c4287ec2fd5c4fa087524e4c16 to your computer and use it in GitHub Desktop.
Save jhowbhz/51efa7c4287ec2fd5c4fa087524e4c16 to your computer and use it in GitHub Desktop.
create job in laravel with crontab in ubuntu 1 in 1 minute
First

Create a job in laravel with command artisan

php artisan make:command ExampleCron --command=example:cron

Second

Navigate to file create in project

app\Console\Commands\ExampleCron.php

Third

Edit method handle, save file

public function handle()
{

    \Log::warning('Testando job');

}
Four

Execute command in root user crontab -e

Five

Create new line */1 * * * * cd /your/directory/project && php artisan example:cron >> /dev/null 2>&1

Read more

https://pt.stackoverflow.com/questions/124518/configurar-cronjob-para-executar-de-5-em-5-minutos-quando-estiver-dentre-5-a-20

*        Todos
1,2,4    Um, dois e Quatro apenas
7-10     De 7 a 10, incluindo 8 e 9
*/5      A qualquer momento, mas com espaço de 5 (ex: 2,7,12,17...)
1-10/3   No intervalo de 1 a 10, mas de 3 em 3 (ex: 2,5,8)

https://laravel.com/docs/5.5/scheduling#introduction

https://linux.die.net/man/5/crontab

Create new job: crontab -e

Check your job is create: crontab -l

In this example I assume you already have laravel and ubuntu 18.04 + installed and configured.

Install a Log-Viewer to verify execute job. https://github.com/ARCANEDEV/LogViewer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment