I want to execute a script every time my server start up. The problem is that I need to be a certain user to execute the script, if I try to do it as root it cant find certain packages (such as ruby).
I try to change to xxx user01.
sudo su user01
/etc/init.d/script start
This doesn't work however.
Best Answer
Running
sudo su user01
in a script does not mean the following commands are sent to the resultant shell. In fact, it likely means a new shell is spawned as user01, which never exits!Two things:
-c 'command...'
argument to su, likesu user01 -c '/etc/init.d/script start'
.chkconfig
orupdate-rc.d
. You also don't want jobs in /etc/init.d that shouldn't be started asroot
. The jobs themselves can feel free to fork to another user account, but should be invoked by root.