Cron Jobs? (Full Version)

All Forums >> [Web Development] >> Server Issues



Message


markhawker -> Cron Jobs? (7/9/2004 13:21:24)

Hi, what exactly are cron jobs? I understand you can automate server processes with them, schedule them to run at specific times, but what types of commands can you run? I've posted rather than read up on the matter as descriptions sometimes can be a bit wiry and it's best to hear 'from the horses mouth' so to speak.

Mark




ou812 -> RE: Cron Jobs? (7/9/2004 14:38:04)

cron jobs, or crontabs, are run from cron, a daemon. The cron allows crontab entries to be run at specified times (month, weekday, days of month, hours of day, hours, minutes etc.). So basically a crontab is a command or script, with whatever you want your script to do, that is executed by cron on a specific time(s).

Does that help?

-brian




dpf -> RE: Cron Jobs? (7/9/2004 14:50:32)

quote:

from cron, a daemon

so what is "a daemon"?




bobby -> RE: Cron Jobs? (7/9/2004 14:54:18)

cron is also a Unix/Linux command... not on Windows servers...

the most basic way to describe a daemon is a program or utility that runs in the background relatively unseen...




dpf -> RE: Cron Jobs? (7/9/2004 14:59:07)

I see....sort of like my daughter when there is housework to be done! thanks




Shirley -> RE: Cron Jobs? (7/9/2004 16:01:59)

quote:

cron is also a Unix/Linux command... not on Windows servers...


Windows 2003 server has scheduled tasks which accomplish the objective... to run a script or program at a scheduled time.




markhawker -> RE: Cron Jobs? (7/9/2004 17:40:10)

Thanks, but what type of commands can be run? The server I am on is Linux so that makes sense. Pardon my ignorance!




bobby -> RE: Cron Jobs? (7/9/2004 17:53:08)

check this out:

http://www.unixgeeks.org/security/newbie/unix/cron-1.html

You may not be able to run cron on a hosted server. You likely won't have permissions to run shell commands... but who knows? It will likely depend on the host, etc.

I've used cron on my desktop at home to schedule updates and such...




ellipisces -> RE: Cron Jobs? (7/12/2004 4:44:30)

cron is a command line interface...

as such you can run almost any linux program from a cron job, (if any of you remember DOSKEY), and you can batch them so it could go like this...

connect to network drive n:
scan n: for virus
backup n:




abbeyvet -> RE: Cron Jobs? (7/12/2004 11:52:02)

The easiset way to explain this is by using an example.

First the Cron daemon.

Basically it is a little program that runs all the time on Linux servers, in the background, unnoticed and mostly doing nothing at all. Every so often (usually every minute), it checks to see if there is anything it should do.

If you want to do something on your site or on the server at a specific time every so-many days, you just need something that the daemon will see when it looks and obey.

This is called a crontab. It's just a file that has information about the minute, hour, day of month or day of week a specific command should be run. When the daemon sees this, it obediently causes the command to run at the given time.

In practical terms, this is very handy.

For example, on a site I manage we send out a newsletter to several thousand people every week. Some messages bounce, sometimes because an address is temporarily unavailable, sometimes because it has disappeared forever.

Dealing with this by hand is a big pain.

So, we have a little program that handles the bounces, resending mail twice in case of errors and then suspending the addresses from the list if they bounce more than twice - on the assumption that at that point they are dead.

This is the command that is in the crontab to make that all happen.


30 1 * * * /usr/bin/wget -O /dev/null -T 0 http://www.domain.com/mail/dailymail.php?pw=passowrd



That looks horrible - but break it down and it is simpler.

30 1 * * *

This bit says when the job should be done, in the order minute | hour | day of month | month | day of week

So my command will run at 1.30 am every day, as I have * * * for day of month, month, and day of week so they are ignored.

another example:

30 1 4 5 *

that could be used to send a birthday greeting to someone at 1.30 am on the 4th of May each year [:D]


The next bits are pretty grim looking:

/usr/bin/wget

This is the command bit - wget is a little tool that grabs a web page, so basically this is saying "go to wget, which is in the directory /usr/bin, and tell it this......"

what it tells it is:

-O /dev/null

which if you are wget means "get the page but do not output it to a browser as you normally would, just run it".

-T 0

This tells it not to time out - in other words to stick with the task it is being given!

http://www.domain.com/mail/dailymail.php?pw=password

This tells it the page to get, and the password it needs to get into it.


Once that has been done the page dailymail.php will run on the server and the code in it will do whatever it has been written to do, which in this case is resend bounced messages.



It's important to note here that Cron did nothing much - all the work was done by the file dailymail.php. All the cron task did was find the file and run it at a specific time. That is what Cron is almost always used for - running a specified program or script at a specified time.

Some hosting setups allow you to enter your own cron tasks, but most do not. However your host will almost certainly be happy to set one up for you.




mrdance -> RE: Cron Jobs? (7/27/2004 12:00:18)

I recommend using VisualCron. It like cron - but for windows.

You can read more here at it's homepage: www.visualcron.com

regards/ Henrik




markhawker -> RE: Cron Jobs? (7/29/2004 9:38:56)

Thanks for the reply Katherine, a very useful and informative read. I'll have a look at the link too Henrik, thanks.

Regards,




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625