0

I'm trying to write a shell script so that when I reinstall my Ubuntu again. I could just run script and retain all the packages. And I'm planning to pass password in form of argument.

My question here is how can i enter into sudo domain without manually entering password. As I'm also planning to design a UI where it can't access the terminal there.

Ex:

./recover.sh password
Braiam
  • 69,112
Pavan
  • 119

2 Answers2

2

Why not just run the script as superuser?

sudo sh recover.sh
Ryan Doherty
  • 1,029
1

You can use...

echo password | sudo -S recover.sh

Password being your sudo password.

From sudo manpage..

-S, --stdin Write the prompt to the standard error and read the password from the standard input instead of using the terminal device.