Add items to crontab: Difference between revisions
Removes superflous methods, removes reference to telnet since I don't believe this is even possible through telnet |
layout changes and grammatical fixes. |
||
(4 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
=== Skills required === | === Skills required === | ||
You must be able to connect to your | You must be able to connect to your QNAP device using [[How_to_SSH_into_your_QNAP_device|SSH]] and edit using a text editor such as [[Using_vi|vi]] or nano. | ||
=== crontab === | === crontab === | ||
The crontab can be used to execute tasks (scripts) based on a recurring schedule | The crontab can be used to execute tasks (scripts) based on a recurring schedule. The crontab is used, for example, to restart the webserver during the night. | ||
To view the content of | To view the content of your crontab, login to your QNAP via SSH and type: | ||
<pre>crontab -l | <pre>crontab -l | ||
</pre> | </pre> | ||
Line 17: | Line 17: | ||
You will see a (small) list of crontab entries. | You will see a (small) list of crontab entries. | ||
== Standard crontab jobs == | |||
The following table contains the standard QNAP jobs that run on schedules. | |||
This list is by no means complete. Jobs may depend on the firmware version, start times may vary. If you find a job on your QNAP, that is missing from the table, add it. The list could help to identify unwanted jobs that regularly wake up your harddisk(s). | |||
{| cellspacing="1" cellpadding="1" border="1" width="100%" | |||
{| | |||
|- | |- | ||
! scope="col" | Default Time<br/> | ! scope="col" | Default Time<br/> | ||
Line 38: | Line 31: | ||
! scope="col" | Explanation<br/> | ! scope="col" | Explanation<br/> | ||
|- | |- | ||
| 0 4 * * * | | 0 4 * * *<br/> | ||
| /sbin/hwclock -s | | /sbin/hwclock -s | ||
| [http://linux.die.net/man/8/hwclock http://linux.die.net/man/8/hwclock]<br/> | | [http://linux.die.net/man/8/hwclock http://linux.die.net/man/8/hwclock]<br/> | ||
Line 46: | Line 39: | ||
| vs_refresh is for share folder space usage calculation (for Network Share Management)<br/> | | vs_refresh is for share folder space usage calculation (for Network Share Management)<br/> | ||
|- | |- | ||
| 0 3 * * 0 | | 0 3 * * 0<br/> | ||
| /etc/init.d/idmap.sh dump | | /etc/init.d/idmap.sh dump | ||
| related to SAMBA Active Directory configuration. Used if security is set to ADS.<br/> | | related to SAMBA Active Directory configuration. Used if security is set to ADS.<br/> | ||
|- | |- | ||
| 0 3 * * * | | 0 3 * * *<br/> | ||
| /sbin/clean_reset_pwd | | /sbin/clean_reset_pwd | ||
| (unclear) might be the new behaviour of the network recycle bin (purging files after a certain amount of days)<br/> | | (unclear) might be the new behaviour of the network recycle bin (purging files after a certain amount of days)<br/> | ||
|- | |- | ||
| 0-59/15 * * * * | | 0-59/15 * * * *<br/> | ||
| /etc/init.d/nss2_dusg.sh | | /etc/init.d/nss2_dusg.sh | ||
| is a job of the Surveillance Station<br/> | | is a job of the Surveillance Station<br/> | ||
Line 93: | Line 86: | ||
== Adding | == Adding entries at the command-line == | ||
Here are a couple of examples that append new entries to the crontab file:<pre>echo "1 4 * * * /share/custom/scripts/custom1.sh" >> /etc/config/crontab | |||
echo "40 5 * * * /share/custom/scripts/custom2.sh" >> /etc/config/crontab</pre> | |||
== Modifying entries == | |||
'''<span style="color:red">Do NOT edit crontab the usual way!</span>''' | |||
On a desktop or server distribution, you would edit a user's crontab with: | |||
<pre>crontab -e</pre> | |||
However, due to the way the QNAP firmware updates crontab, it will be '''overwritten''' on the next reboot. Obviously, you want your automation to survive reboots, so edit the crontab file directly with your text editor: | |||
<pre>vi /etc/config/crontab</pre> | |||
or | |||
<pre>nano /etc/config/crontab</pre> | |||
== Restart the daemon == | |||
When you're done, reload the crontab file and restart the cron daemon: | |||
<pre>crontab /etc/config/crontab && /etc/init.d/crond.sh restart</pre> | |||
== Notes == | |||
Don't forget to make your scripts executable! Otherwise they will silently fail! You tested your script, right? | |||
<pre>chmod +x filename.sh</pre> | <pre>chmod +x filename.sh</pre> | ||
[[Category:Adding new services]] | <div><span style="font-size:smaller">''These instructions have been tested on various versions of QNAP firmware from 3.6.0 onwards.''</span><br/></div> [[Category:Adding new services]] |
Latest revision as of 16:49, 12 December 2016
Background
Skills required
You must be able to connect to your QNAP device using SSH and edit using a text editor such as vi or nano.
crontab
The crontab can be used to execute tasks (scripts) based on a recurring schedule. The crontab is used, for example, to restart the webserver during the night.
To view the content of your crontab, login to your QNAP via SSH and type:
crontab -l
You will see a (small) list of crontab entries.
Standard crontab jobs
The following table contains the standard QNAP jobs that run on schedules.
This list is by no means complete. Jobs may depend on the firmware version, start times may vary. If you find a job on your QNAP, that is missing from the table, add it. The list could help to identify unwanted jobs that regularly wake up your harddisk(s).
Default Time |
Job |
Explanation |
---|---|---|
0 4 * * * |
/sbin/hwclock -s | http://linux.die.net/man/8/hwclock |
0 3 * * * | /sbin/vs_refresh | vs_refresh is for share folder space usage calculation (for Network Share Management) |
0 3 * * 0 |
/etc/init.d/idmap.sh dump | related to SAMBA Active Directory configuration. Used if security is set to ADS. |
0 3 * * * |
/sbin/clean_reset_pwd | (unclear) might be the new behaviour of the network recycle bin (purging files after a certain amount of days) |
0-59/15 * * * * |
/etc/init.d/nss2_dusg.sh | is a job of the Surveillance Station |
10 15 * * * | /usr/bin/power_clean -c 2>/dev/null | ? |
4 3 * * 3 | /etc/init.d/backup_conf.sh | does an automatic backup of several config files in /etc/config. |
0 3 * * * |
/bin/rm -rf /mnt/HDA_ROOT/twonkymedia/twonkymedia.db/cache/* |
Will clear the Twonky media cache |
5 0 * * 1 |
/etc/init.d/antivirus.sh scan 1 |
If Antivirus is enabled, this will scan the files for viruses |
0 0 * * * |
/etc/init.d/antivirus.sh archive_log |
If Antivirus report jobs are enabled |
0 0 */1 * * |
/etc/init.d/antivirus.sh update_db |
If Antivirus is enabled, this will check clamav.net for updates |
/etc/init.d/startup |
If a restart/powerof job is configured in power management | |
/etc/init.d/poweroff |
If a restart/powerof job is configured in power management |
Adding entries at the command-line
Here are a couple of examples that append new entries to the crontab file:
echo "1 4 * * * /share/custom/scripts/custom1.sh" >> /etc/config/crontab echo "40 5 * * * /share/custom/scripts/custom2.sh" >> /etc/config/crontab
Modifying entries
Do NOT edit crontab the usual way!
On a desktop or server distribution, you would edit a user's crontab with:
crontab -e
However, due to the way the QNAP firmware updates crontab, it will be overwritten on the next reboot. Obviously, you want your automation to survive reboots, so edit the crontab file directly with your text editor:
vi /etc/config/crontab
or
nano /etc/config/crontab
Restart the daemon
When you're done, reload the crontab file and restart the cron daemon:
crontab /etc/config/crontab && /etc/init.d/crond.sh restart
Notes
Don't forget to make your scripts executable! Otherwise they will silently fail! You tested your script, right?
chmod +x filename.sh