shell script - getting the prompt back.

ittechlab
ittechlab used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
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 FavorFractional CTO
Distinguished Expert 2018

Commented:
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 Developer

Commented:
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.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Distinguished Expert 2017

Commented:
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
Most Valuable Expert 2016

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 Engineer
Distinguished Expert 2018

Commented:
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.
- 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 Support

Author

Commented:
i usually run bash -x myscript.sh

what is the difference between
bash -x -v myscript.sh
bash -x myscript.sh
nociSoftware Engineer
Distinguished Expert 2018

Commented:
-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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial