Friday, 27 September 2013

Executing bash commands automatically under sudo is not working

Executing bash commands automatically under sudo is not working

I need a script to execute sudo commands without requesting a password. In
the following scripts I have a strange bash stdin behaviour:
username@username-laptop:~$ sudo -Si | echo "password"
password
root@username-laptop:~# exit
username@username-laptop:~$ sudo -Si | echo "password"
password
[sudo] password for rootname:
(password is a root password on my machine)
Why the password has not been requested in the first time, and has been in
the second (and always after that)? Also I don't understand how stdin
works in bash, where is an error in my code?
I know this is a very bad idea to put a root password to the command
directly, but I need it to execute correctly.

No comments:

Post a Comment