If you want to run something as a user other than root, there are a number of ways to do that. It is called "dropping privileges". If you have no special requirements around how the environment is preserved, how capabilities are inherited, or how PAM configurations are applied, then the simplest way from a shell script context is probably to use /bin/su
. For example,
su $someuser -c /usr/local/bin/$dir/$script
See man su
for more information on that tool.