Add items to crontab: Difference between revisions

From QNAPedia
Jump to navigation Jump to search
Removes superflous methods, removes reference to telnet since I don't believe this is even possible through telnet
OneCD (talk | contribs)
m added cron daemon restart
Line 17: Line 17:
You will see a (small) list of crontab entries.
You will see a (small) list of crontab entries.


<span style="color:red;">Do NOT edit the crontab in the usual way</span> Normally you can edit a user's crontab with
<span style="color:red">Do NOT edit the crontab in the usual way</span> Normally you can edit a user's crontab with
<pre>crontab -e</pre>
<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 read the section below on how to modify and persist changes to cron on QNAP
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 read the section below on how to modify and persist changes to cron on QNAP




Line 32: Line 32:
The following table is meant to bring some light into those built-in jobs.The 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 in the table, add it. The list could help to identify unwanted jobs on the QNAP&nbsp;that regularly wake up your harddisk(s).
The following table is meant to bring some light into those built-in jobs.The 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 in the table, add it. The list could help to identify unwanted jobs on the QNAP&nbsp;that regularly wake up your harddisk(s).


{| width="100%" cellspacing="1" cellpadding="1" border="1"
{| cellspacing="1" cellpadding="1" border="1" width="100%"
|-
|-
! scope="col" | Default Time<br/>
! scope="col" | Default Time<br/>
Line 99: Line 99:
Here is an example which assumes you are ssh'd into your nas (as admin).
Here is an example which assumes you are ssh'd into your nas (as admin).
<pre>echo "1 4 * * * /share/custom/scripts/custom1.sh" >> /etc/config/crontab
<pre>echo "1 4 * * * /share/custom/scripts/custom1.sh" >> /etc/config/crontab
echo "40 5 * * * /share/custom/scripts/custom2.sh" >> /etc/config/crontab
echo "40 5 * * * /share/custom/scripts/custom2.sh" >> /etc/config/crontab</pre>
crontab /etc/config/crontab</pre>
 
Then reload crontab and restart cron daemon:
<pre>crontab /etc/config/crontab
/etc/init.d/crond.sh restart</pre>


PS. Don't forget to make your scripts executable! Otherwise they will silently fail! You tested your script, right?
PS. 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>


Tested on 3.6.0&nbsp;: works fine.&nbsp; Tested on 4.2.1 [[User:Freephile|Freephile]] ([[User talk:Freephile|talk]]) 01:21, 28 July 2016 (CST)
Tested on 3.6.0&nbsp;: works fine.&nbsp; Tested on 4.2.1 [[User:Freephile|Freephile]] ([[User_talk:Freephile|talk]]) 01:21, 28 July 2016 (CST)
[[Category:Adding new services]]
[[Category:Adding new services]]

Revision as of 04:42, 7 December 2016

Background

See Cron on Wikipedia

Skills required

You must be able to connect to your qnap using SSH and edit using vi.

crontab

The crontab can be used to execute tasks (scripts) based on a recurring schedule; by default the crontab is used, for example, to restart the webserver during the night.

To view the content of the crontab, login to your qnap using ssh and type:

crontab -l

You will see a (small) list of crontab entries.

Do NOT edit the crontab in the usual way Normally you can 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 read the section below on how to modify and persist changes to cron on QNAP


Stock crontab jobs

When using crontab -l on a default QNAP, QNAPs has some default crontab jobs.

Usually you will want to know, what default jobs are running on the QNAP based on schedule.

The following table is meant to bring some light into those built-in jobs.The 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 in the table, add it. The list could help to identify unwanted jobs on the QNAP 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/Changing cron entries

Edit /etc/config/crontab directly, then tell the cron service to reload the crontab. These changes will persist past a reboot. Like any changes to cron, you should test your script thoroughly before adding it.

Here is an example which assumes you are ssh'd into your nas (as admin).

echo "1 4 * * * /share/custom/scripts/custom1.sh" >> /etc/config/crontab
echo "40 5 * * * /share/custom/scripts/custom2.sh" >> /etc/config/crontab

Then reload crontab and restart cron daemon:

crontab /etc/config/crontab
/etc/init.d/crond.sh restart

PS. Don't forget to make your scripts executable! Otherwise they will silently fail! You tested your script, right?

chmod +x filename.sh

Tested on 3.6.0 : works fine.  Tested on 4.2.1 Freephile (talk) 01:21, 28 July 2016 (CST)