Getting sudo and nohup to work together Getting sudo and nohup to work together linux linux

Getting sudo and nohup to work together


The solution is to use the -b flag for sudo to run the command in the background:

$ sudo -b ./ascii_loader_script.pl 20070502 ctm_20070502.csv

You should only use nohup if you want the program to continue even after you close your current terminal session


The problem here, imho, is not nohup, but background processing sudo.

You are putting the process in background (& at end of command) but probably sudo needs password authentication, and that is why the process stops.

Try one of these:

1) remove the ampersand from end of command, reply to passord prompt and afterwords put it in background (by typing CTRL-Z - which stops the process and issuing the bg command to send it to background)

2) Change the /etc/sudoers to not ask for users password by including the line:myusername ALL=(ALL) NOPASSWD: ALL

If besides the password reply your application waits for other input, then you can pipe the input to the command like this:$ cat responses.txt|sudo mycommand.php

hth


You can Try

sudo su

and then

nohup ./ascii_loader_script.pl 20070502 ctm_20070502.csv &

instead of

nohup sudo ./ascii_loader_script.pl 20070502 ctm_20070502.csv &