DD-WRT:CRON/de

Einführung
Cron, auch als crond, ist ein Dienst, der auf in der DD-WRT-Systeme können gedreht werden. Cron ist die Standard-System-Scheduler-Prozess innerhalb eines Systems unter Linux und anderen * nix-Varianten. Ältere Versionen von DD-WRT Linux verwenden Sie den Namen und Befehl cron, in neueren Builds der Name cron hat crond geändert worden, aber sie die gleiche Arbeit.

Cron können in der Services / Dienstleistungen (v23) ​​oder Verwaltung / Management (v24) Abschnitt der Web-Interface von DD-WRT aktiviert werden.

Wenn cron beim DD-WRT Gerät Boot beginnt, wird nach cron-Job Anweisungen. Diese können direkt im Web-Interface von DD-WRT (GUI) eingegeben werden, oder für fortgeschrittene Benutzer, gespeichert in den Dateien an bestimmten Orten (siehe unten). Wenn cron Anweisungen als Dateien gespeichert sind, werden sie 'crontab' Dateien genannt. Siehe die Links am Ende dieses Artikels für die Formatierung von cron-Job Anweisungen.

Voraussetzungen
Da Cron führt Befehle nach mindestens der aktuellen Zeit, sollte das Datum und die Zeit, die normalerweise auf NTP werden auf dem Gerät ausgeführt DD-WRT. Mit der Zeit und Datum Satz so wichtig ist, wird die Konfiguration für NTP direkt in der ersten Setup-Seite unter Basic / Setup Basic befindet.

Sie können das aktuelle Datum und die Uhrzeit in der GUI, indem Sie überprüfen:
 * Status/Router/Current Time
 * Sie können auch die Zeit in der Shell-Schnittstelle, indem Sie 'date'.

Um sicherzustellen, dass Cron / Crond aktiviert ist, gehen Sie zu: und sicherstellen, dass es so eingestellt ist, zu ermöglichen.
 * Administration/Management/Cron

Cron Job Instruction: Standorte
Cron job instructions can be stored in at least three locations on DD-WRT: It is important that you include "root" before the command, otherwise the command will not run as specified. The examples, in external links above or elsewhere, leave off prefixing commands with "root". External examples outside this Wiki and DD-WRT, are designed for common multi-account Linux systems: cron normally runs instructions inside crontab files as dependent on whichever user created them. Without using "root", your test only works in telnet or ssh (eg Putty) because you already logged in as root.
 * 1) Put your crontab-formatted instructions in the Web Interface cron box on the Administration->Management screen. This is the easiest method. Using stopservice cron && startservice cron in the console will store those commands in /tmp/cron.d/cron_jobs. Files stored in /tmp are cleared out at reboot time so it would be wise to preserve a copy of any needed commands, ideally using a mounted filesystem or an SD card if your router is equipped with one.
 * 2) Crontab files can be created and saved in /tmp/cron.d, which is stored in RAM and lost when restarting the DD-WRT device or loss of power. Commands added to the cron_jobs file are displayed on the Administration->Management page. As noted above, using stopservice cron && startservice cron will store those commands in /tmp/cron.d/cron_jobs.
 * 3) Crontab files can be stored in /jffs/etc/crontab, if you use the JFFS filesystem. See JFFS.

Andere Methoden, ältere Versionen
Other methods and older versions of DD-WRT echo ' *      *       *       *       *       root /bin/date > /tmp/test.txt' >> /tmp/crontab
 * Add your command to the file /tmp/crontab. The added job instructions are erased during restart. The following command in a Startup Command in the GUI, or script file (.sh) stored in one of the locations the DD-WRT device scans during startup with the extension *.startup (See Wiki article Script Execution):

which will look like this in the /tmp/crontab file:

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

echo '* * * * * root /bin/date > /tmp/test.txt' > /tmp/cron.d/date
 * Create a file in the /tmp/cron.d/ folder (eg. /tmp/cron.d/dosomething) using crontab formatting. A script file executed during startup, or in the Startup Command in the GUI, might look like this:

Looks like this in the dosomething file:

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

Neustart 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: Older versions of DD-WRT: Newer versions of DD-WRT:
 * stopservice cron && startservice cron
 * stopservice crond && startservice crond

Note: v24sp1 deletes the /tmp/cron.d directory when the cron service is stopped. You should stop the service, make the /tmp/cron.d directory, put your cron script in that directory, then restart the cron service.

Weitere Informationen
You can add this to your Startup Commands (Administration -> Diagnostics in the web UI), before you add any jobs. 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 interpreted properly if you don't invoke the shell manually (/bin/sh -c).

Note: If your device is using v23sp1, the startup script is broken, so you will want to save all this as the "firewall" script.

If you add this to your Startup Commands, you will see this in the /tmp/crontab file:

# |     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
 * 1) minute (0-59),

$PATH Unterschiede
Cron runs with a different $PATH variable than you have in your shell when you Telnet/SSH to the router. The $PATH variable contains locations for the shell to look for applications when you try to run a them without a full path to the application. This means that Cron may not find programs you're trying to use. You can either check what the full path to apps is using the which command and then use the full path within your scripts, such as /usr/bin/uptime instead of just uptime, or you can check what your $PATH is by running echo PATH=$PATH in your shell and then copying the output to the top of your crontab or script.

root@DD-WRT:~# which uptime /usr/bin/uptime

root@DD-WRT:~# echo PATH=$PATH PATH=/bin:/usr/bin:/sbin:/usr/sbin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin:/mmc/sbin:/mmc/bin:/mmc/usr/sbin:/mmc/usr/bin:/opt/sbin:/opt/bin:/opt/usr/sbin:/opt/usr/bin

CRON Dienst Einschlafen in V24
The cron service is frequently falling asleep and cron jobs are not executed. This requires a stopservice cron; startservice cron or a reboot. V23 does not have this problem.

Working Directory
Cron runs with the same working directory that you have when you Telnet/SSH to the router which is:

root@DD-WRT:~# pwd /tmp/root

If you're saving files without a path then they'll end up in this directory. Be sure your paths to files are correct so that you're not looking for them in the wrong places.

externe Links

 * Articles containing 'CRON' on the DD-WRT Wiki
 * Unix Man Pages: Cron
 * Crontab : Scheduling Tasks
 * Dreamhost crontab wiki
 * Cron Job in cPanel
 * Cron Jobs (Automated Processes)
 * Crontab Explained
 * Wikipedia Crontab

en:DD-WRT:CRON es:DD-WRT:CRON fr:DD-WRT:CRON it:DD-WRT:CRON pl:DD-WRT:CRON pt:DD-WRT:CRON ru:DD-WRT:CRON se:DD-WRT:CRON th:DD-WRT:CRON zh-tw:DD-WRT:CRON