Thursday, January 13, 2011

Linux : Provide password to sudo on same prompt

Hi All,

As we know whenever we need to execute some script/program on Mac/Linux with root permissions for a user, then we run that script with "sudo". E.g

$sudo ./some_script
password:

After execution of the command on terminal, a password prompt comes and waits for user to provide password. I have been searching for the methodology that will not wait for password prompt. Because lots of coding efforts needs to be provided to provide password on "password" prompt.
So, the solution is simple, just type -

$ echo password | sudo -S ./some_script

I have sudo 1.7.0 version installed on my Ubuntu machine.
This will not wait for the password prompt and you would be able to run ./some_script with sudo permissions.


3 comments:

  1. Nice work Akash ... It's really good you started a platform for discussing issues :)

    One small addition ... You can add this command to .bashrc file so that you won't have to give the command explicitely ... but it's for your personal use only :P

    ReplyDelete
  2. True, but if I am developing some application for redistribution then its not good practice to ask the user to modify his .bashrc file.

    ReplyDelete
  3. Nice! though I don't know what exactly the problem was :P

    just kiddin!

    ReplyDelete