Friday 30 May 2014

Cron Job in ubuntu with php


Hi Friends Today iam working on cron job, it is Easy Process.....

If we put the file in cron, It will run automatically by setting the time limit. Using time limit we have run the file every min/hour/day/month etc.

First open terminal (Ctrl+Alt+t)
srinu@srinu-GA-78LMT-S2:~$ sudo su

Enter password

root@srinu-desktop:/home/srinu# crontab -e
If you are using the cron in first time, First you should select the editor. It(crontab -e) will show five editor. Then you have to select the editor. Here nano editor is very useful in this, so you should select the nano editor.

How to select the nano editor
sudo /usr/bin/select-editor Put this command in command prompt, It will show more editor like...
1 /usr/bin/vim
2 /bin/ed
3 /bin/nano
4 /usr/bin/vim.basic
5 /usr/bin/vim.tiny
Here you have to select nano editor, ie, Number 3. After select the editor, It will go to cron file.
In cron file we have to set time for run our file, In my case running file evry 5mints so

*/5 * * * * /usr/bin/wget -q http://localhost/cron_test/test.php
After that save the file using command (ctl+x), Yes,press Enter.
test.php file will be calling every 5 minutes automatically.
How to edit the cron job
crontab -e
How to list the cron job
crontab -l
How to remove the cron job
crontab -r
Crontab syntax:
*    *    *    *    *  command to be executed
┬    ┬    ┬    ┬    ┬
│    │    │    │    │
│    │    │    │    │
│    │    │    │    └───── day of week (0 - 6) (0 is Sunday, or use names)
│    │    │    └────────── month (1 - 12)
│    │    └─────────────── day of month (1 - 31)
│    └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)

No comments:

Post a Comment