homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

cron job
how to do it

 8:09 pm on Feb 5, 2013 (gmt 0)

So I understand cron job is some sort of linux server instruction.
I am wanting to send an email every 7 days. How do I do this with cron job - assuming cron job is the best solution.



 8:33 pm on Feb 5, 2013 (gmt 0)

cron is a unix system of starting processes at defined intervals.

Over the years (unix dates back many decades), cron has a evolved a bit and the capabilities have hence also expanded.

Essentially there is a table (mostly nowadays per user) that defines what needs to be started when. It's called a crontab.

Most unices allow a user to list their cron entries you have with the command
$ crontab -l
most also allow the user to edit their entries with the command
$ crontab -e
It'll use your favorite editor if you set any, vi other wise - which you might dislike if you're not an old time unix user. (type :q! to quit in that case and set the appropriate editor settings)

It's without a doubt the very best way to start something recurring if you have shell access to a user on a unix machine. It's highly reliable and rather flexible.

The format of a crontab line is 6 fields (separated by spaces or tabs):
col1: minute
col2: hour
col3: day of month
col4: month
col5: day of week
col6: the command (can include spaces all it wants)

Uncommon unix machines (essentially unix v7 machines) had only one global crontab and included a 7th field (before the 6th) that told cron to run the command as which user)

A star in one of the fields means "every"

0 0 * * 0 /path/command

will start every sunday a midnight
(0 is sunday, 1 is monday, ... 6 is saturday, 7 is sunday as well)
(on every month every day of the month)

more modern variants also support shorthands like @weekly (which is defined to mean "0 0 * * 0")
and/or things like */5 (every 5)
and/or ranges like 4-8 (at 4, 5, 6, 7 and 8)
and/or en enumeration like 1,2,3,5,8,13

The output of the command is email locally to the user running the command (so if your email is configured properly you get the output in an email).

root's cron should have a number of system maintenance commands in it for inspiration.

There is a process running on every unix system called "cron" that reads the crontab(s) and spawns the needed commands at the right time.

That's in a nutshell and non specific to the different flavours of unix.


 9:07 pm on Feb 5, 2013 (gmt 0)

Wow, thanks, so how do I incorporate that into my code?


 10:08 pm on Feb 5, 2013 (gmt 0)

Command line access to you unix machine is required to use cron.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved