• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

running a bash command in background

Red Squirrel

No Lifer
How do I run a bash command completly in background and inderpendant of my session?

I have a script that prompts for a few values then runs a command using & at the end.

But I want to be able to close the ssh console, and the program continues. If I close the ssh console, then it stops the process.
 
One way is to use nohup, e.g.

nohup whatever.sh &

I think "console" does the same thing, but lets you reconnect to the output stream again later, or something. I've never used it.
 
You can use nohup but after that it won't be possible to reattach to the process. You can see the commands output in the nohup.out file, unless you redirect it somewhere else but that's about it.

I personally prefer screen.
 
I also use screen for this. Install screen with your package manager and then just type 'screen' to get into a session. Some useful commands within screen are "ctl-a, ?' for help, 'ctl-a, d' to detach from your screen session ( you can then exit the ssh console and screen will keep running in the background ), 'ctl-a, c' to create a new screen "window", 'ctl-a, n' to go to the next "windows", 'ctl-a, p' to go to the previous "window", and 'ctl-a, " ' to list all "windows". I used to keep these commands on a little cheat sheet next to my monitor, but they are so useful I used them enough to have them memorized in about a week.

After detaching from a screen session, you can reattach with 'screen -r', or show all screen session with 'screen -ls' but I always just open one session and then use ctl-a, c to create multiple windows within that session. You can get more info with 'man screen' or 'screen --help'.
 
Back
Top