CRON

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 13:37, 27 October 2006 (edit)
Yaoge123 (Talk | contribs)
(restart cron)
← Previous diff
Revision as of 05:09, 31 October 2006 (edit) (undo)
Whiteboy (Talk | contribs)

Next diff →
Line 1: Line 1:
The ''crontab'' command, found in Unix and Unix-like operating systems, is used to schedule commands to be executed periodically. [http://wiki.dreamhost.com/index.php/Crontab Dreamhost crontab wiki] has a good explanation of how crontab works. A more official explanaton can be found [http://en.wikipedia.org/wiki/Crontab here]. The ''crontab'' command, found in Unix and Unix-like operating systems, is used to schedule commands to be executed periodically. [http://wiki.dreamhost.com/index.php/Crontab Dreamhost crontab wiki] has a good explanation of how crontab works. A more official explanaton can be found [http://en.wikipedia.org/wiki/Crontab here].
- +=Prerequisites=
-== Pre-requisites ==+
In order for cron to function properly, you must have the date and time set correctly. In order for cron to function properly, you must have the date and time set correctly.
You can check this in the GUI by going to: You can check this in the GUI by going to:
Line 17: Line 16:
and set it to enable. and set it to enable.
-== File Locations ==+==File Locations==
Cron can be set in two locations on dd-wrt: Cron can be set in two locations on dd-wrt:
Line 37: Line 36:
-== Restarting Crond ==+==Restarting Crond==
After you modify/add the appropriate command you will need to restart cron in order for your changes to take effect. You can restart crond with the following command: After you modify/add the appropriate command you will need to restart cron in order for your changes to take effect. You can restart crond with the following command:
stopservice cron && startservice cron stopservice cron && startservice cron
Line 43: Line 42:
'''Since end of June cron changed to crond!!!''' '''Since end of June cron changed to crond!!!'''
-== Extras ==+==Extras==
You may wish to add this to your startup script (Administration -> Diagnostics in the web UI), before any jobs are added. It will add clarity to your crontab file: You may wish to add this to your startup script (Administration -> Diagnostics in the web UI), before any jobs are added. It will add clarity to your crontab file:
/bin/sh -c 'echo "# minute (0-59)," >> /tmp/crontab' /bin/sh -c 'echo "# minute (0-59)," >> /tmp/crontab'
Line 65: Line 64:
# | | | | | commands # | | | | | commands
-== External links ==+=External Links=
* [http://www.math-linux.com/spip.php?article45 Crontab : Scheduling Tasks] * [http://www.math-linux.com/spip.php?article45 Crontab : Scheduling Tasks]
* [http://blog.micfo.com/2006/08/26/cron-explanation Cron Explanation] * [http://blog.micfo.com/2006/08/26/cron-explanation Cron Explanation]
[[Category:English documentation]] [[Category:English documentation]]

Revision as of 05:09, 31 October 2006

The crontab command, found in Unix and Unix-like operating systems, is used to schedule commands to be executed periodically. Dreamhost crontab wiki has a good explanation of how crontab works. A more official explanaton can be found here.

Contents

Prerequisites

In order for cron to function properly, you must have the date and time set correctly. You can check this in the GUI by going to:

  • Status
    • Router tab
      • Current Time.

You can also check the time in the command line by using the 'date' command.

You must also enable crontab in DD-WRT before you can use it. You can enable crontab in the GUI by going to:

  • Administration
    • Management
      • Cron

and set it to enable.

File Locations

Cron can be set in two locations on dd-wrt:

1. Either by putting your command in the /tmp/crontab file

echo '  *      *       *       *       *       root /bin/date > /tmp/test.txt' >> /tmp/crontab

which will look like this:

  *      *       *       *       *       root /bin/date > /tmp/test.txt

2. Or by putting a file in the /tmp/cron.d/ folder (eg. /tmp/cron.d/dosomething) that holds your command

echo '* * * * * root /bin/date > /tmp/test.txt' > /tmp/cron.d/date

which will look like this:

* * * * * root /bin/date > /tmp/test.txt

You must add the items you wish to CRON to the startup(broken) or firewall scripts to make them exist after the router restarts. To do this, follow the example under "Extras"


Restarting Crond

After you modify/add the appropriate command you will need to restart cron in order for your changes to take effect. You can restart crond with the following command:

stopservice cron && startservice cron

Since end of June cron changed to crond!!!

Extras

You may wish to add this to your startup script (Administration -> Diagnostics in the web UI), before any jobs are added. It will add clarity to your crontab file:

/bin/sh -c 'echo "# minute (0-59)," >> /tmp/crontab'
/bin/sh -c 'echo "# |      hour (0-23)," >> /tmp/crontab'
/bin/sh -c 'echo "# |      |       day of the month (1-31)," >> /tmp/crontab'
/bin/sh -c 'echo "# |      |       |       month of the year (1-12)," >> /tmp/crontab'
/bin/sh -c 'echo "# |      |       |       |       day of the week (0-6 with 0=Sunday)." >> /tmp/crontab'
/bin/sh -c 'echo "# |      |       |       |       |       commands" >> /tmp/crontab'

Please note: Things that execute in the startup script are invoked without a shell, so stdout and stderr pipes will not be interperted properly if you don't invoke the shell manually (/bin/sh -c). also note: In DD-wrt v23 sp1 the startup script is broken, so you will want to save all this as the "firewall" script.


If you add this to your startup script, you will see this in your crontab file:

# minute (0-59),
# |      hour (0-23),
# |      |       day of the month (1-31),
# |      |       |       month of the year (1-12),
# |      |       |       |       day of the week (0-6 with 0=Sunday).
# |      |       |       |       |       commands

External Links