Jump to content

Scheduling a daily event


Calvin770D

Recommended Posts

I am assuming you are linux....I know it can be done on windows, but don't know how.

 

i actually rely on this quite a bit, so I'll give you some pointers (for unix)

 

open a shell as the user who will be running the script.  (IE if the script needs root privileges then you need to be in a root shell).  type in crontab -e

this will open up a nano editor with a line of text that looks like:

 

# m h dom mon dow  command

 

This is where you specify the schedule and the script.  Google search for how to specify the timing (it's easy), but a daily job, run at midnight all days of the week would look like:

 

 0 0 * * *

 

When you specify the scrip, you have to be specific, as cron's shell won't necessarily load the same env variables as your bash shell, so the 'PATH' variable may not be set.

 

So to be safe, call the script as

/usr/bin/php  /absolute/path/to/script.php &> /dev/null

 

Without the &> /dev/null, output and errors are sent as mail to the crontab's owner, which (for me) is a PITA, especially with the jobs I have running every minute.  You can also redirect to a log file by changing /dev/null to the path of the log file.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.