From what it looks to me you should consider using sudo for your task.
There you can allow in a very detailed way certain commands to be executed
without giving a password. Hardcoding the root password into a script as
you try seems to me very risky...