To create a cron for a user, log in as the user.
1) su $user
2) crontab -e
3) min hr date mon day /home/$user/$domain-www/path/to/script
where
min - minute (00 - 59)
hr - hour of day (00 - 23)
date - day of month (01 - 31)
mon - month of year (01 - 12)
day - day of week (00 - 06)
4) save changes
5) exit
However where you want a script in php to work you have to put in a little more.
Here's the instructions when php runs only as an apache module
Say you are user star and you want to run a php program(say
http://www.star.com/exp.php) from cron and output the results to a file /home/star/phptest2
Telnet into the system as star
create a file (say /home/star/cronjob)
Add the folllowing lines to it
SHELL=/bin/bash
MAILTO=star@starinc.com
0 * * * * /usr/bin/wget -O/home/star/testphp2
http://www.starinc.com/exp.php
The above syntax means that at the start(0) of every hour(*) of every day(*) of every month(*) of every year(*), wget will run the exp.php and output the contents to testphp2. And when this runs, it will send a mail to
star@starinc.com
Save the above file
now run crontab /home/star/cronjob
This will automatically add it to cron and execute it at the designated time
If you do not want to output the results anywhere simply omit
-O /home/star/testphp2
To view the contents of cron simply type crontab -l
to remove tasks from cron simply type crontab -r
Say you are user root and you want to run a system critical php program(say
http://www.starinc.com/exp.php) every hour from cron and output the results to a file /home/star/phptest2 here's what you do
ssh into the system as root
create a file say( /etc/cron.hourly/phpcron)
Add the folllowing lines to it
#!/bin/sh
/usr/bin/wget -O/home/star/testphp2
http://www.starinc.com/exp.php
save and chmod to 755
Here cron automatically reads /etc/crontab , detects all scripts in /etc/cron.hourly (in our case phpcron) )and executes them
For hourly , daily, weekly and monthly, store your scripts in /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly respectively
I hope this helps.
Have a great day
Regards
Amar