You could change the owners id to the one you want using chown and then execute a chmod 6755 (I think 6755 is correct; I don't have a Unix box on site to check) on the file to set the setuid bit on execution. Not a recomemended method for root owned shell scripts though. Bit of a security hole.
alternatively call su within the script. working from memory here so check the syntax.
This script simple runs if you are the root user or prompts for the password and then calls itself if you are not.
#!/bin/sh
# If I'm not root login and run script
# otherwise just run the script
if ( `uid` != 0 )
su - root -c ${0} # call myself
# The password prompt appears here
else
# run the commands
....
....
fi
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.