Crontab on MyCloud EX2

Adding my config updates here for reference:
Inside the <list> element, I added:
<name id="9">BackupToUSB</name>

Then, just under the closing tag of the list element (</list>) - notice the escaped values in the run tag:
<BackupToUSB>
<count>1</count>
<item id="1">
<method>3</method>
<1>0</1>
<2>2</2>
<3>*</3>
<4>*</4>
<5>*</5>
<run>rsync -vuar /mnt/HD/HD_a2/Main /mnt/USB/USB1_c1/ &gt;/var/log/BackupToUSB 2&gt;&amp;1</run>
</item>
</BackupToUSB>

1 Like

@lepomis , apologies for bring up this old thread. After my crontab changes being overwritten on reboots, I decided to follow this thread and modify the config.xml. Afterwards, my drive is no longer booting up, like you mentioned yours was. I don’t seem to be able to connect to it via ssh either. I just wanted to ask how you got around that problem?

Edit: Holding the reset button in for 40 seconds fixed the config file, removed users/shares etc, but importantly kept all the data.

I struggled through this today and finally got a working solution at the end of the day. I’ll leave a few notes:

  1. Do not try to leave any of the number fields empty in the cron config or use non-standard time keywords like @reboot. This (temporarily) bricked my device!
  2. Thanks @gary20 for the tip about holding reset for 40 seconds. This is unfortunately pretty difficult to do correctly as the button needs to be held in with a paperclip at the same time as you plug in the NAS and prevent the button from coming unpressed. I had to try 3 times before triggering the reset correctly. It did eventually work though!
  3. After resetting I was happy to see that my installed apps (entware) and packages from opkg were not deleted. A few bindings had to be recreated, just make sure you keep as many files as possible on the /mnt/HD/HD_a2 drive and you’ll be ok.
  4. I missed this crucial point the first time @andrewismoody mentioned it. You must add the entry in the list at the start of the crond section, or your crontab entry won’t be created. Once I did this, my startup task worked!

ETA: An important note to add! If you have several crontab entries you need to insert, you may be tempted to add a single crontab entry to /usr/local/config/config.xml to execute a script that adds additional crontab entries by piping an edited crontab file to crontab -.

This will work
 only temporarily. I was surprised to find this morning that my cron jobs had not run, and when I checked the crontab I saw my entries were missing. It seems that the crontab is refreshed from the config.xml file whenever the machine goes to sleep and wakes up, or something like that.

My solution is to just add the crontab entries directly in /usr/local/config/config.xml instead of using a secondary script.

However another solution could be to insert the crontab modifications before the line in the bootup script that prevents the rest of the script from running more than once. Because the bootup script deletes itself from the crontab whenever it’s run, the before-once-only instructions will run once every time the crontab is regenerated.

I want to add an additional note about editing /usr/local/config/config.xml as I have tripped up on this multiple times, needing to hard reset my device each time. Make sure to edit with tabs, not spaces.

If you’re editing with vi as I was, it may not be obvious that you’ve used the wrong formatting. I no longer trust myself to make changes in vi without bricking everything, so now my usual routine for editing this file to avoid problems is:

  1. SSH into the machine and make a copy of the file in your Public share: cp /usr/local/config/config.xml /mnt/HD/HD_a2/Public. This way you can access the file for editing from a visual code editor on your local machine, which makes it easier to see tabs/spaces.
  2. While making edits, remember to always use real tabs, and to follow all the other points I mentioned in my previous comment above. Make sure everything is aligned well. The MyCloud seems to be very picky about this.
  3. You will probably need to save it as a new filename since the original copy won’t be editable without superuser permissions. So I save as config1.xml.
  4. Back in SSH on the machine, do cp /mnt/HD/HD_a2/Public/config1.xml /usr/local/config/config.xml, which replaces the original config.xml file. Then you can delete your copies in the Public share.

I agree about nano being more intuitive than vi but it has the same problem with tabs versus spaces not necessarily being obvious. I think editing with a visual editor that emphasizes tabs/spaces is a good idea in order to avoid surprises.

Note that with MyCloud EX2 and OS 5, edits to the /usr/local/config/config.xml file would no longer persist across reboot.

I ended up having to install Entware for OS 5 via: Cloudsmith - Repositories - WD Community (wd-community) - EX2Ultra (EX2Ultra) - Packages and then installed crontab via Entware: Using Cron · Entware/Entware Wiki · GitHub

This seems to have done the trick, and also addressed the issue with ssh-keygen not persisting across reboot either, since installing Entware also modifies the local path of the “root” user and allows for these changes to remain. :+1:

Hope this helps anyone else trying to achieve the same thing.

2 Likes

That is actually the way.
Using entware actually helped me activate the 5minutes cron and it survives reboots and all. Excellent idea.