• 9849-xxx-xxx
  • noreply@example.com
  • Tyagal, Patan, Lalitpur
cron job
Cron Job

Cron Job

Here are some information I have gathered required for cron job. Hope this will help you. ?

Cron Job List

crontab -l

Open cron job editor

// Open in Vim
crontab -e

// Open in nano
VISUAL=nano crontab -e

Disable mail alerts

// Add this at top of job file.
MAILTO=""

Adding job

Click here to find various Cron Examples required to set for your jobs. Also, I find helpful using crontab-generator too. Crontab-generator helps you to see whole line of code based on your requirement. I highly recommend to check that site.

* * * * * cd location_to_your_project && your_command_goes_here >> /dev/null 2>&1

// eg.
// /public_html/storage/logs/laravel.log was provided to store the log information. You can use any other location to store logs.
* * * * * cd ~/public_html/ && php artisan schedule:run >> /public_html/storage/logs/laravel.log 2>&1

// Still not working? 
// You can ignore logs by replacing /laravel.log to '/dev/null' as shown in below.
* * * * * cd ~/public_html/ && '/opt/alt/php74/usr/bin/php' 'artisan' schedule:run >> '/dev/null' 2>&1

How did I find php path? It’s so simple. Just type following command in terminal and boom 🤯. In command section, you will get php path. Just copy from php path to artisan and paste it in your cron job code. Isn’t that easy? 👽

php artisan schedule:list

Change visual editor

// If nano
export VISUAL=nano;

// If vim
export VISUAL=vim;
Tags :

Leave a Reply

Your email address will not be published. Required fields are marked *