You can't easily do what you ask (i.e. make sudo startup.sh run as a named non-root user). What you can do, though, is one or both of the following
Tell users to use
sudo -u tomcat /path/to/startup.shinstead ofsudo /path/to/startup.sh, and disallow the latter anywayAdd this line to your
sudoers(remembervisudo) such thattomcathere is the target user account. Change the firstALLto a list of users if there are only certain people allowed to run the script as the target userALL ALL=(tomcat) /path/to/startup.shMake the script perform the
sudo, and disallowsudo -u rootfor the script. You'll need #1 (above). Ensure thattomcathere matches thetomcatinsudoers.#!/bin/bash # targetUser=tomcat if [[ $UID -ne "$(id -u "$targetUser")" ]] then exec sudo -u "$targetUser" "$0" "$@" exit 1 fi # ...script continues but as the $targetUser...This allows people to run
/path/to/startup.sh(or even juststartup.shif it's in the$PATH) and not worry about thesudopart.