Scheduled Jobs in Linux using crontab (nano)

  1. Create crontab file: crontab -e
    This command will enter VI
  2. Edit crontab file
    e..g */1 * * * * php /var/html/task.php
    Execute task.php every minute.
  3. Ctrl + C to enter VI command mode and enter :wq to exit VI
#Execute send_order_emails every 5 mins
#and write warning/error/echo results in /tmp/stage_email.log
*/5 * * * * /usr/bin/php /var/www/stage/index.php /web/send_order_emails/a6aec3 >> /tmp/stage_email.log 2>&1

Line break for log:

echo $order->email . ': ' . print_r($result, true) . PHP_EOL;

Nano commands:

Select: ALT + M + A
Copy: ALT + 6
Paste: CTRL + U (Copy from nano)
Paste: Shift + Ins (Copy from other applications)

Note:

  • Make sure use full path to use php. e.g. /usr/bin/php index.php
  • PHP could execute URI of CodeIgniter
    /usr/bin/php /var/www/test/index.php /home/some_action

Reference: