sudo, use in script without prompt for password

I need to create an automated script where I have to use sudo to switch to multiple user so the script stops and prompts for password, Is there a way I can provide the password in same command only?

Remember that, I cannot disable the password settings of sudo as I dont have rights.

According to man sudo:

Remember to restrict read access to the script to hide the password.

[quote=eagleflyfree;302310350]
According to man sudo:

I am new to UNIX so have problems in the syntax, can you please provide me the syntax.

Currently I use

sudo -su weblogic
propmt.."pw"

how should I use it now? I tried using -S "pw" multiple places and it did not work.

#!/usr/bin/expect

spawn ssh [ lindex $argv 0 ]
expect "*?assword:*"
send -- "abcd1234"
send -- "\r"
expect eof

in this example password is abcd1234, replcaethat string with your password.
for this script to execute you have to install expect.

This works if you want ot ssh into another machine.

Sorry about the delay.

echo "password" | sudo -S -su weblogic

-S makes sudo "read the password from stdin", and this is what it means; it takes input from its standard input, to which you can redirect the output of something else, like echo printing out the actual password.
Again, make sure your script is only readable by the concerned users, because anyone who can cat it will see the password.