How can i invoke SU command in shell script

Hi All ,

i am trying to switch user (from unix1 to unix 2 ) The user will give me the input and also the password . also how can i login into with the password . itried several attempts . no luck

Can any one help on this !!!

You should use sudo for this(security...), since it can be configured in a way that user1 can sudo -su user2 without asking a passwd... and use it in scripts
e.g. of sudoers:
opersad ALL=/usr/bin/su - dbasad -c save_*,...

i tried to use su command and it was able to login to different user .. but there it stops and not able to execute the rest of my shell script ..

any thing you guys can suggest ???

su -c "echo hi" user

Code :

# su - <new_user> -c "bash script_to_be_executed"

Cheers.....