How I can start 2 threads from shell?

I'm new in shell programming.

1) I want to start 2 node.js processes from *.sh file: node script1.js node script2.js

2) I want to start it when system is loading (on a system start up).

How I can do this?

  1. To start a process in background, start it with & at the end:

    node script1.js &
    
  2. What distribution are you using? Startup scripts might be located in /etc/init.d

You can add crontab entries as well. Use crontab -e to edit:

@reboot /PATH/TO/SCRIPT1/script1.js
@reboot /PATH/TO/SCRIPT2/script2.js

This will start those scripts at startup.

You also need to enable crond service via sys v / BSD init style system. Under RHEL / CentOS / Fedora, you need to use chkconfig (ntsysv) command to enable crond on boot:

chekconfg crond on

Under Debian / Ubuntu Linux use update-rc.d as follows to turn on service on boot:

update-rc.d cron defaults