How to login as a different user inside a shell script?

hi,

i want to login as a different user inside a shell script and then call another shell script from that script.

how to do that?

original script : script_A.sh

so when the script_A.sh is called , i want to login as a different user and then call another shell script(script_B.sh) from script_A.sh.

how can i do that??

if the user you are using present in sudousers list then you can try below inside script_A.sh

sudo -u user script_B.sh

ok but it will ask for the password.. how can i provide the password automatically so that it doesnot prompt for it..

This is where you have to edit your sudoers file under "User privilege specification" section

<<your mainuser>> ALL=(<<user you want to sudo>>:<<user you want to sudo>>) NOPASSWD: ALL

make sure there are no other line below that such as %admin which might override your line :slight_smile: