Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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.
share|improve this answer
    
i like the "dirty workaround"... –  amphibient Sep 17 '13 at 14:51
1  
He could also launch it in screen instead of backgrounding it. –  jordanm Sep 17 '13 at 15:04

sudo cannot prompt you for a password and read it because it is executing in the foreground. Run sudo in the foreground and arrange for it to run your program in the background.

sudo sh -c 'nohup myscript.sh &'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.