switching between root and a normal user

I am writing a script that has some tasks that must be run as root, then set of tasks to be run as normal user, then again as root.

is there a way to switch between users in a script?
any other alternatives?

thx

Does your system have sudo?

if you start the script with root, you can use # su - user -c "command"

when the command has finished it automatically switches back to root

If you have sudo facility in your system

you can do like this

sudo "command"    #executed as root

"command"           #executed as normal user (if you log in as normal user)

"command"

sudo "command"    # again executed as root