login into root from user and execute command through script

i have logged in as user.

I want to write a script to login into root and execute commands for eg. ifconfig or other command.

kindly help me out.

sudo should allow you to do what you require.

$ cat myscript.ksh
ssh -l root HOSTNAME
echo "WELCOME to ROOT"
<do your stuff>
exit

$ sh myscript.ksh >> myscript.log

Will prompt for the password of root and you have to give manually.

i know the password of root.

I want to write the script in such a way that it should not promt for the passwd and directly login into root

i dont think host name is required. Because i am working in same system.

If any user would be allowed to run that, try a SUID script.

With sudo, you can control who can execute the command as root, and whether or not they need a password for that.

can u explain in detail

sudo tutorial - Google Search