2

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.

Fulvio
  • 925
  • 2
  • 13
  • 21

3 Answers3

3

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).

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
2

(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.

Community
  • 1
  • 1
Stack Overflow
  • 2,416
  • 6
  • 23
  • 45
0

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
lulyon
  • 6,707
  • 7
  • 32
  • 49