To switch to a general user and execute commands while you are a root user , su su < Use the -c option of / strong.
su --username -c command
I've been writing web applications lately, but recently I've been wondering what is the best way to switch from a root user to a regular user and run the application. This is because I want the web application to run automatically when the server starts and I want to manage the web application from the root user.
I'm wondering which is better, su or sudo, but I think su is better because it may have a default setting that sudo can only be executed from the terminal (tty). It's a bit annoying to have to enclose the command in double quotes, though.
As a sample, write the following shell.
#! / bin / sh PERL_BIN = / home / gitprep / perl5 / perlbrew / perls / perl-5.16.3 / bin su --gitprep -c "PATH = $PERL_BIN: $PATH / home / gitprep / webapp / gitprep / gitprep $*"
The point is that you need to set the PATH properly. Because I am not logged in to the terminal, the .bashrc that is editing the PATH is not loaded. Which Perl to use must be specified if the default Perl is not used.