Bash script to automatically give an interactive value to prompt.
[WHEN]
For instance, you need to execute a sudo command on user logon, and you need to do it through a script.
[HOW]
Edit a bash script with the following content:
#!/bin/sh
( echo 'P4ssw0rd
' ) | su - root -c "/sbin/rcnetwork restart"
Where:
P4ssw0rd is the password for root user
"/sbin/rcnetwork restart" is the command to execute as root user
Take special attention on the new line after the password on the bash script, and also on the single quotes.
[NOTE]
This is only for reference, you never should write out the root password on a plain text file.