I am new to linux environment and trying to write few services and want to start each of them via single shell script but not able to do so.
I have few linux executable placed under subfolders of application. It is like:
MainApp
AppAFolder
App-A
AppBFolder
App-B
startServices.sh
I want to run each of the applications present in sub-folders in background forever(even after main terminal is closed).
When I try below commands separately in Linux terminal, it starts the services.
cd AppAFolder && chmod +x App-A && ./App-A &>/dev/null & disown
or
cd AppBFolder && chmod +x App-B && ./App-B &>/dev/null & disown
But, when i place same commands inside shell script and try to execute, it seems to be changing directory and second service does not run.
#!/bin/bash
echo "Starting ServiceA. Currect dir is : $PWD"
ACmd="cd AppAFolder && chmod +x App-A && ./App-A &>/dev/null & disown"
$ACmd
echo "Starting ServiceB. Currect dir is : $PWD"
BCmd="cd AppBFolder && chmod +x App-B && ./App-B &>/dev/null & disown"
$BCmd
I get error "./startServices.sh: line 12: cd: AppBFolder: No such file or directory".
I want to spwan each service in new terminal in background and detach from main process so that it can run forever untill stopped.
Please let me know what I am missing here.
Thanks, Pooja