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.

 

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <small> <sup> <sub> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <h4> <img> <br> <br /> <p> <div> <span> <b> <i>
  • Lines and paragraphs break automatically.

More information about formatting options