shell script - getting the prompt back.

when i start the application using a specific command, its does spawn a process however a i am not getting the prompt back.  I have been told you to press CTRL+C to get the prompt.

This is usual behavior for starting the application.

How do i get the prompt back using the shell script?

[root@myserver]# bash -x /etc/init.d/app start
....
output omitted

^C
Session terminated, killing shell... ...killed.


when i run #ps -ef | grep app, i noticed the process is running. when i talk to the app support, they said its normal behavior.  Not sure why this happens.
ittechlabLinux SupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
When you start an application in foreground, you will see a new command prompt under two circumstances...

1) Command reaches completion. In this case you command prompt will hang, till your command completes.

Typing CNTL-C kills/terminates/stops the running command.

2) Command run detaches itself + begins running in background.

You can also explicitly run a command in background by appending an & character to end of your command.
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Likely you'll do the following...

bash -x /etc/init.d/app start &

Open in new window


And no way to be sure, without knowing what /etc/init.d/app contains.
Duncan RoeSoftware DeveloperCommented:
Bash does not have - -x flag. Perhaps the author mis-typed the Q and is using bash -c?
Any well-written script in /etc/init.d should return to shell prompt reasonably quickly.
/etc/init.d/app start

Open in new window

should be sufficient (no need for bash -c).

CORRECTION: Bash does have a -x flag, but the effect of using it is to output all executed commands to stderr. Somehow I don't think you can be doing that.
Get a highly available system for cyber protection

The Acronis SDI Appliance is a new plug-n-play solution with pre-configured Acronis Software-Defined Infrastructure software that gives service providers and enterprises ready access to a fault-tolerant system, which combines universal storage and high-performance virtualization.

arnoldCommented:
sounds like the "app" does not release with the user expecting it to go into the background on its own.

nohup /etc/init.d/app start &
nohup separates the script from your shell such that when you terminate your session it will not terminate the process the app spawns.
Gerwin Jansen, EE MVETopic Advisor Commented:
Are you building some start scripts yourself? Scripts in init.d usually start (services) in the background. Is the 'app' something that you are writing?
nociSoftware EngineerCommented:
Maybe you should check on the steps for daemonizing a program.
In General:
Mostly this means closing stdin/stdout/stderr reopening them to /dev/null
then forking the process and continue working in the CHILD process.
The parent should only save the pid of the child (f.e. /var/run/app.pid) so a stop procedure can find your daemon.  
It also gives a chance the let the parent do some initialising while privileged and having the child run in a less privileged account.  

If the child needs to run as root and the you might be able to getaway with:

app >/dev/null </dev/null 2>&1 &
echo $$ >/var/run/app.pid

Open in new window


or with a log file:
app >/var/log/app.log </dev/null 2>&1 &
echo $$ >/var/run/app.pid

Open in new window


Many distros used to have a toolkit like daemontools which would do this a bit better then above two lines.

as startup command.
Bernard S.CTOCommented:
- you are not sure what happens whan you launch the app

- if it is a sh or bash script, you can check what happens when running the script by using, as suggested

bash -x -v myscript.sh

- this will display on screen how the script is run /interpreted
- of course this does not work for non-script programs
ittechlabLinux SupportAuthor Commented:
i usually run bash -x myscript.sh

what is the difference between
bash -x -v myscript.sh
bash -x myscript.sh
nociSoftware EngineerCommented:
-x shows commands executed (exec calls).
-v shows commands when parsed (input handling).

-x -v   is combined...
See bash manpage.

https://linux.die.net/man/1/bash
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.