Fulvio
Fulvio

Reputation: 965

How do I get shell prompt back after execute script

i'll need some help to get back the prompt, right now i'm executing this block and don't throw me back the prompt, i'm using & at the end for run this command as a background task. how can get back to prompt after execute the script.

#!/bin/sh
sudo su - user << EOF
   nohup program -p4xxx &
EOF

nota: if i press ctrl + c - kill the program.

Thank you in advance.

Upvotes: 2

Views: 6538

Answers (3)

glenn jackman
glenn jackman

Reputation: 246774

Without testing, I'm wondering if you want this:

#!/bin/bash
nohup sudo -u user program -p4xxx &
disown

That will background the sudo process, and disassociate it from the calling shell (the script).

Upvotes: 3

lulyon
lulyon

Reputation: 7225

Two alternative:

  1. Bring background job foreground with fg and send signal with ctrl+c
  2. Directly kill background process(correspond to program job) with pkill program

Upvotes: 0

Stack Overflow
Stack Overflow

Reputation: 2764

(From https://askubuntu.com/questions/121559)

After you start a process (job), you can still do other things. You might want to write these down as a cheat sheet.

  1. Ctrl+c Kill the running process (foreground job)
  2. Ctrl+z Pause running process (foreground job) and return to the prompt
  3. Type jobs Shows you all background jobs on the terminal
  4. Type bg Makes the last paused job continue in the background
  5. Type fg Returns the last pause job to the foreground

You can also type bg or fg with a number after, like fg 3. This will bring job #3 to the foreground.

Upvotes: 2

Related Questions