Use sudo with password as parameter [closed]
Solution 1:
The -S switch makes sudo read the password from STDIN. This means you can do
echo mypassword | sudo -S command
to pass the password to sudo
However, the suggestions by others that do not involve passing the password as part of a command such as checking if the user is root are probably much better ideas for security reasons
Solution 2:
You can set the s
bit for your script so that it does not need sudo
and runs as root (and you do not need to write your root password in the script):
sudo chmod +s myscript
Solution 3:
echo -e "YOURPASSWORD\n" | sudo -S yourcommand