Dear visitor, in case we do not cover a topic you are looking for, then feel free to ask in our freshly created forum for IT-professionals for a solution. We hope our visitors can help you out with your questions. Have a good one. ~ Tom.

How to add custom scripts on QNAP NAS devices

QNAP NAS WebGUI

You can add custom scripts to the crontab on your QNAP NAS box. I’ll use it to create a timestamp file in a directory that will be synchronized in real time to a off-site NAS. I’ll check at the off-site NAS if the file is periodically updated to be sure the synchronization is working.

List your crontab contents
crontab -l
Adding entries via command-line
echo "1 4 * * * /share/custom/scripts/custom1.sh" >> /etc/config/crontab
echo "40 5 * * * /share/custom/scripts/custom2.sh" >> /etc/config/crontab

Create the required crontab timeformat here: https://crontab.guru

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
Example of timestamp file for monitoring purposes

This sample prints the current timestamp to a file. We’ll monitor off-site the last change date of the file.

*/30 * * * * echo $(date -u) > /share/CACHEDEV1_DATA/allgemein/timestamp.txt 2>&1

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.