sudo is one option to avoid passwords for specific commands so if you don't actually need a root shell, then this might be the best way to go. Just make sure you used the "NOPASS" option in the sudo specification like this:
username ALL=NOPASSWD: /bin/ping, /bin/command2, /sbin/command3
second alternative is to just run the script as root. What I mean is just write your script as normal and then use sudo to run the script itself.
third option... use "expect". Expect is a script language that operates like the old modem scripts. You can define text you expect as prompts and what you want to send when the script sees these prompts on stdin. I don't advise using this method as it is the most insecure way to do this.
forth option is to use suid bit on the script. *** this is a major security risk ***
Here is an example of something I've set up to allow users to burn iso to cd/dvd media.
I created a wrapper script for cdrecord called /usr/bin/burniso containing the following:
#!/bin/sh
sudo cdrecord -v dev=8,0,0 -dao driveropts=burnfree "$@"
Then, I added the following lines to my /etc/sudoers file:
mylogin ALL=NOPASSWD: /usr/bin/cdrecord
%users ALL = /usr/bin/cdrecord
What this does is allow me to run cdrecord without password but when any other user runs it, they have to type in their own password.