0

I have 1000 of javascript files, and I would like a way to launch all of them under debian. For instance, on windows I had this:

start start2.bat
node myBot1.js

And then here is what's in the start2.bat:

start start3.bat
node myBot2.js

This way, I could start all of my bots under windows, but now I am wondering how may i do that under debian?

Emma
  • 27,428
  • 11
  • 44
  • 69
Zayonx
  • 164
  • 1
  • 12
  • 1
    So you have 1000 bat scripts on windows, one for each js script? Any reason you don't have one bat script that launches the 1000 js scripts? The following would launch all the js scripts of a directory, if that works for you : `for script in ./*.js; do node "$script"; done` – Aaron Feb 16 '19 at 18:35

2 Answers2

3

To just run the node command on a given script, I dont see the point of having a 100 bash scripts as you can simply just:

 node scriptA.js

If you had a wrapper script called run_A.sh which had the contents above, you would run it as:

bash run_a.sh

For a single script to run them all, one at a time, write a scrupt called run_all.sh as follows:

for JS in *.js
do
   echo "Starting $JS"
   node $JS
done

Then:

 bash run_all.sh

Or, if you want to run them as one large script(if that is applicable):

cat *.js > all.js
node all.js

Both the above assume the script names determine the order to run them.

TenG
  • 3,843
  • 2
  • 25
  • 42
  • This is not working because a node instance can only handle 1 file. And no, it is not applicable to run all of them in one file ;x – Zayonx Mar 12 '19 at 18:02
1
run-parts - run scripts or programs in a directory

That's the tool anacron uses for executing all files in /etc/cron.daily etc.

Just start run-parts /foo/bar and all files in /foo/bar with the executable flag will be started sequentially.

run-parts runs all the executable files named within constraints described below, found in directory directory. Other files and directories are silently ignored.

   If neither the --lsbsysinit option nor the --regex option is given  then  the  names  must
   consist  entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores,
   and ASCII minus-hyphens.

   If the --lsbsysinit option is given,  then  the  names  must  not  end  in  .dpkg-old   or
   .dpkg-dist  or  .dpkg-new  or  .dpkg-tmp,  and must belong to one or more of the following
   namespaces: the LANANA-assigned namespace (^[a-z0-9]+$); the LSB hierarchical and reserved
   namespaces  (^_?([a-z0-9_.]+-)+[a-z0-9]+$);  and the Debian cron script namespace (^[a-zA-
   Z0-9_-]+$).

   If the --regex option  is  given,  the  names  must  match  the  custom  extended  regular
   expression specified as that option's argument.

   Files  are  run  in  the  lexical  sort  order  (according to the C/POSIX locale character
   collation rules) of their names unless the --reverse option is given, in which  case  they
   are run in the opposite order.
Michael D.
  • 1,795
  • 2
  • 18
  • 25
  • `.js` files aren't executable themselves, are they? Looks like they need to be run by `node`, can `run-parts` handle that? – Xen2050 Feb 17 '19 at 05:30
  • 1
    you can make any file in linux executable by executing `chmod +x file`. If `file` is not a binary, it will need a https://en.wikipedia.org/wiki/Shebang_(Unix) line ie. `#!/usr/bin/node` – Michael D. Feb 17 '19 at 09:35
  • I see, I was mainly wondering if `.js` files have the right format, and will be run with `run-parts`? It appears they don't, so won't work with `run-file`... Testing "beacon.js` (from saving this webpage) I tried making it executable, and the shell just tried to execute every line (didn't work). `run-parts` ignored the .js file, even when it was executable, so this answer would not work... right? Renaming it to "bea" (with no .js extension) still said *"failed to exec bea: Exec format error"* – Xen2050 Feb 18 '19 at 01:46
  • see https://stackoverflow.com/questions/24253027/node-and-shebang-help-executing-via-command-line#24253067 – Michael D. Feb 18 '19 at 10:29