Problem with feeding password while changing to root user

i want to change user to "root" from another user while running a script. how can i automatically feed the password? for example, i want to write a script say "script.sh"... it will first run the command "p" as mhmn user, and then it will change the user to "root" by using "su - root" command. at this point it asks for the password for root. say the password is "blue". i want to feed the p.w. automatically while it asks for it. inside script.sh it will look something like-

 
#p
#su - root 
(feed p.w. automatically here)
#p

That's not possible, except if the user is a member of the wheel group and PAM is configured to allow it.

Configuring sudo is probably the better way to go. Giving carte blanche access to root using su in this way is generally not a good idea.

1 Like