Q:

start pm2 processes on system boot using a shell script

I was looking on how to write a SHELL script that:

Change the working directory to directory path/to/dir/A
Then get's all the ".js" files in directory path/to/dir/A/X
And iterates over them all one by one with this command "pm2 start {files in directory A}"

I'm new to SHELL scripting so any help is welcome.
Just to add, those files are pm2 config files to start different processes. Each process has its own file. Thus the need to iterate over all of them.

A:

I'm not sure what X is in the question, but seeing how you've accepted an answer that ignores X, here is my solution:
for fname in /path/to/A/*.js; do
    pm2 start "$fname"
done

This simply loops over a glob expanding to all .js files in A and runs pm2 start on them.

In case the process needs to be started from a specific directory, you do have to cd into it. After edits to the question:
cd /path/to/A
for fname in X/*.js; do
    pm2 start "$fname"
done

