Jump to content

cron


smiley_kool

Recommended Posts

On the system type this in the command line:

crontab -e

This will create the crontab if it is not already created, or append if one already exists.

 

Next, you'll need to understand how the entries work. The first part is telling your system when to run the job. There are 5 switches to use:

* * * * *
|  | |  | +-What day of the week (0 being sunday)
|  | |  +-What month (0 being january)
|  | +-What day of the month (0-31)
|  +-what hour (0-23)
+-What minute (0-59)

The * means that it's a wildcard, it will run no matter what that column represents so long as all other columns match. All 5 * means it will run every second of every day. Not a good thing, so do not run that. But say you want to run something on the hour every hour, say updatedb.

0 * * * * updatedb

That will run the command updatedb every time the minute is 0. Say the same every 12 hours.

0 12 * * * updatedb

I think you should get the idea from that. If you want to run a script, sometimes you may have to include the path to the the execution program for that script type, say PHP, and with that you can run the PHP script itself:

0 0 * * * /usr/bin/php -q /path/to/the/php/script.php

The -q flag will make it run quietly and not push errors out and screw up other stuff, downfall is that it may not report any errors, so you won't know if it runs that well. I prefer to run shell scripts in my crontab and in that bash script, I give all output to a log file I create, that way I can go back and find out if things go wrong, or have a date stamp of when it worked. Hope that helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.