Page 1 of 1

How to run a Batch Job like in Windows

PostPosted: Tue Nov 06, 2018 1:29 pm
by latiron
Howdy all. I am new to the ASUSTOR NAS devices. I have extensive Windows Desktop OS knowledge, but not much in the way of command line. And most all my server experience is from a GUI. I am not a programmer nor understand any of the programming languages. Therefore, it is very hard for me to understand scripting and all that. I do, however, know a little about how to create and run batch files in Windows.

I currently have 3 batch files running from my Windows 10 Pro laptop, which create xml files for my EMBY Server that is running on the ASUSTOR NAS. Obviously this is not ideal, otherwise I might as well run the EMBY Server from my Windows computer.

So, since this box seems to be linux based, can anyone help me with how I can run some kind of scheduled task like Windows does, that will run daily, weekly and or monthly in whatever is equivalent to running a batch file in windows? I would very much appreciate it.


Re: How to run a Batch Job like in Windows

PostPosted: Sat Nov 17, 2018 6:10 am
by sigvind
you can probably use crontabs, I'll give you a quick few tips since I did this myself with some success.
I cannot give any guarantees for success for you, or grants for further follow ups or help;-)
The steps involved touch parts of the NAS thas in use for the standard functions of the NAS and you may cause malfunction to those functions if you do things wrong.

Read up on e.g. and understand the syntax of Cron files.

If you are unfamiliar With Linux (as me) prepare yourself for a steep Learning curve, but lots of fun too. There are a number of pitfalls like f.ex access rights, line endings in files (use an editor that offers LF as line endings) and oddities in the Linux Version on the NAS.

On my Device I edited /var/spool/cron/crontabs/root, adding a line for a periodic bash script.
I think I used SSH and the small nano editor, started With the command
nano /var/spool/cron/crontabs/root
CTRL^O to save CTRL^X to exit
Might be an idea to backup the file first, in case you destroy the syntax in the file. Cron is used for a number of the built-in functions on the NAS too.
Add a line for your script.

After changing the cron config file I had to restart the Cron service:
/etc/init.d/S41crond stop
/etc/init.d/S41crond start

The script might have a different name in Your /etc/init.d folder.
I made a small script to start with, that just appended a line to a file, and then I tested that the Cron service did the Call at the inteval I configured.

The line I added to call a script at 8 o'clock in the morning every day was:
0 8 * * * su -c '/bin/sh /home/admin/' admin

Play around a bit with bash scripts first, there are many things to learn there too, before you try to automate the activation of them.