Here is the case. I have bash script that requires a couple of command to be executed. First of all, it requires sudo
, then answer (y/n
) and then password one more time. What I want to do is I want to execute it in one command.
Let's say I have my bash script - myscript.sh
. This script requires sudo
to be executed. So, to execute it in one line I can write:
echo 'mypassword' | sudo -S bash myscript.sh
And this will work. But after script is executed I need to answer y
and type password one more time. How can I do that?
Here is what I have tried:
printf '%s\n mypassword y mypassword' | sudo -S bash myscript.sh
echo 'y\nmypassword\n' | echo 'mypassword' | sudo -S bash myscript.sh
And there were a couple more of what I have tried, but it didn't work.