0

I have a Linux server and in this I want to execute a cron job for sending birthday mail to all my friend with a PHP program. I want to create a php program that read data from database and send the mail.

I want to know the command of cron job to execute the program on every day automatically. I have no knowledge of Linux commands.

Dan Grossman
  • 51,866
  • 10
  • 112
  • 101
Abhishek
  • 63
  • 2
  • 7

3 Answers3

3

You will want to read up a little bit on the 'crontab' command but basically you will do this.

From a linux command prompt run the crontab command.

Then add this entry:

* * * * * php yourscript/path

You can set what time by modifying the * values. See this URL for information on that:

http://adminschoice.com/crontab-quick-reference

Dan Grossman
  • 51,866
  • 10
  • 112
  • 101
Roloc
  • 1,910
  • 2
  • 13
  • 16
  • 1
    That would run every minute of every day. crontab is not run under your own user, so its PATH is different, and it's *very* common to not even include /usr/bin, so best to specify the full path to the interpreter. – Dan Grossman Feb 05 '11 at 07:13
  • 1
    Why was this answer downvoted? Roloc said that the * values have to be modified... – Lukas Eder Feb 05 '11 at 07:21
  • It clearly states that the * values should be modified, with a link to another URL that fully explains the sometimes confusing to new users crontab syntax. However yes the path should be absolute as it will run under whatever users you have your cron jobs running as. – Roloc Feb 05 '11 at 07:34
2

This is the command to add to your crontab file:

0 0 * * * /usr/bin/php /path/to/your/script.php

Adjust the paths to the PHP interpreter and your script as necessary. It will run your script every day at midnight.

Dan Grossman
  • 51,866
  • 10
  • 112
  • 101
1

This is done using a cron table in unix systems, including linux. Check out some example documentation:

You'll find many more, if you google for crontab, or if you check out the man crontab pages on your linux box

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509