Editing crontab for QNAP, and making it stick

If you have a QNAP you may want to run some scripts regularly. Editing the crontab seems to work but your changes don't survive a reboot. There is however a fairly simple solution:

During boot, the QNAP will mount the partition /dev/mtdblock5 in /tmp/config and execute the file autorun.sh in this directory, if it exists. The following steps show you how to create the file with the commands necessary to add a crontab entry:

First, mount the partition, cd into the config directory and edit or create the autorun.sh file:

    mount /dev/mtdblock5 /tmp/config
    cd /tmp/config
    vi autorun.sh

Then, enter the following:

    #!/bin/sh
    crontab -l >/tmp/crontab.tmp
    echo '0 19 * * * some-command' >>/tmp/crontab.tmp
    crontab /tmp/crontab.tmp

The above script will dump the standard crontab to a temporary file, append your entry and then replace the crontab with the edited version. Naturally you substitute whatever you want done for some-command and set the time rules appropriately.

Finally, you must make autorun.sh executable by root and unmount the partition:

    chmod u+x autorun.sh
    umount /tmp/config

This has been tested on a QNAP 109 but probably works on other models as well.

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Refresh Type the characters you see in this picture.
Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.