Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to run a command sudo apt-get update &. However after hitting enter, when i hit for jobs, it shows the status of these commands as stopped. My guess is that by pushing the process into background I did not provide it an opportunity to ask password. Is there a way to run a process in background which requires a password ?

share|improve this question
add comment

3 Answers 3

Try typing sudo -i first end then apt-get update & or just running the command:

sudo -i && apt-get update &

Something else you could try is the command:

gksudo && sudo apt-get update &

But I'm not sure if that'll work.

Or you could try adding your user to the list of users that aren't required to enter a password when using sudo.

To do this add type sudo visudo into the terminal. Then add the line

%super_sudoers ALL=(ALL) NOPASSWD: ALL

Or whatever you want to call the group (you can change "super_sudoers") and then add your user to that group by typing

usermod -a -G super_sudoers yourusername (obviously replacing yourusername with your username)

and reboot (or maybe log out/log in works, not sure) to find you can type suo commands without needing to enter a password. This, of course, means other people can so ensure you always leave your computer locked and don't have automatic login enabled.

share|improve this answer
    
You mean both in separate lines .. ? –  bubble Dec 2 '12 at 16:53
    
That will mean logging as a root first.. But I would like to avoid it –  bubble Dec 2 '12 at 16:55
    
your solutions a very risky, I believe –  bubble Dec 2 '12 at 17:06
add comment

First of All, "This is not the best practice".
But you can use the command sudo -S

Sudo -S:
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.

So, Go to the terminal and type:

echo 'yourpassword' | sudo -S apt-get update 1>> /home/user/myaptupd.log 2>&1 &

it will run the command apt-get update without prompt for a password and backgroud,
and will redirect (append) the stdout and the stderr to a log file in your home named myaptupd.log, just in case you can check if everything is allright with the apt-get update command.

Do to this is a large command, you can put this command as an Alias in your .bashrc file. Eg: In the terminal type:

gedit /home/user/.bashrc

Add this line to the end of the file

alias myaptupd='echo 'yourpassword' | sudo -S apt-get update 1>> /home/user/myaptupd.log 2>&1 &'

Reload your .bashrc
In the terminal go to your home directory just type:

cd

Then type:

source .bashrc

or

. .bashrc

Now in the terminal just type the Alias as a command:

myaptupd

You can check with the command jobs the status.

On the other hand you can create a bash script and named myaptupd.sh
Eg:

#! /bin/bash
echo 'yourpassword' | sudo -S apt-get update 1>> /home/user/myaptupd.log 2>&1 &

For security you can set the perms to:

chmod 700 /path/to/the/myaptupd.sh

Then you can call the script with:

 bash /path/to/the/myaptupd.sh

Or make an Alias in your .bashrc

alias myaptupd='bash /path/to/the/myaptupd.sh'

Reload your .bashrc (like explain it before) and you can type the name of the alias to run the script:

myaptupd

Hope this will helpful!

Regards.

share|improve this answer
add comment

Try:

xterm -e "sudo -b nohup php -S localhost:80 -t /media/malcolm/Workspace/sites &>/dev/null"

when you close xterm, the php web server still alive,

Don't put "nohup" before "sudo" or else php web server will be killed after closing xterm.

share|improve this answer
add comment

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.