- Create crontab file: crontab -e
This command will enter VI - Edit crontab file
e..g */1 * * * * php /var/html/task.php
Execute task.php every minute. - Ctrl + C to enter VI command mode and enter :wq to exit VI
1 2 3 |
#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:
1 |
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:
- https://kb.iu.edu/d/afiz
- http://linux.vbird.org/linux_basic/0430cron.php#crontab
- http://stackoverflow.com/questions/15470016/how-to-write-cron-job-in-aws-ec2-server
- Debug:
https://stackoverflow.com/questions/7397469/why-is-crontab-not-executing-my-php-script - Write logs:
https://askubuntu.com/questions/56683/where-is-the-cron-crontab-log - Usage of VI:
http://linux.vbird.org/linux_basic/0310vi/0310vi.php - Nano usage:
https://www.linuxquestions.org/questions/linux-newbie-8/how-to-copy-paste-a-line-in-nano-editor-548925/