Shell – “nohup sudo …” does not prompt for passwd and does nothing

background-processnohupshellsudo

When I run

nohup sudo myscript.sh &

I only get something like

[1] 1220

in return and do not get prompted for a password. The process does not start either.

I want to run this script in the background and it needs to be run under sudo.

Anybody guess what I am doing wrong? Using OSX Mountain Lion (Darwin).

Best Answer

The problem is that you are putting sudo in background. I see two ways to solve this problem:

  1. remove the ampersand, enter your password and then pause the task with Ctrl+Z and then run bg so the job resumes running in the background ;
  2. dirty workaround: do a dummy sudo before (like sudo ls), then launch your nohup command, and it won't ask for your password again and will run anyway.
Related Question