LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Run a (service) command as a normal user during start up (https://www.linuxquestions.org/questions/linux-newbie-8/run-a-service-command-as-a-normal-user-during-start-up-761452/)

mycoolwater 10-12-2009 03:56 PM

Run a (service) command as a normal user during start up
 
I have found so many ways for root user to execute commands in so many possible path locations - but having difficulties on executing commands as normal user - during start up.

This is what i've got for /etc/rc.d/rc.local script:

Code:

su -l user && (/bin/sh svc_cmd.sh &)
But the command doesn't run at all... any better idea than above?

(this thread sort of a continued question of this: -thread-)

catkin 10-12-2009 04:14 PM

Quote:

Originally Posted by mycoolwater (Post 3716910)
Code:

su -l user && (/bin/sh svc_cmd.sh &)
But the command doesn't run at all... any better idea than above?

A few ideas. What's that -l option on the su command? According to the man page (on Slackware 13) there's no such option. Secondly, how will /bin/sh find svc_cmd.sh? It would have to be in the current directory for it to work and what is the current directory when the boot scripts are running? /? You could try giving the full path to svc_cmd.sh. Finally the su command will complete and if it completes successfully, after it has exited, the command line will run /bin/sh svc_cmd.sh & as root. Maybe this is closer to doing what you want to do:
Code:

(su - user -c /bin/sh <full path to>/svc_cmd.sh )&
Is there any particular reason for using /bin/sh rather than /bin/bash?

EDIT: as the command is going to be backgrounded and is a single command, the suggested command is pointlessly complex and can more simply be
Code:

su - user -c /bin/sh <full path to>/svc_cmd.sh &

mycoolwater 10-13-2009 04:59 PM

Thanks!


All times are GMT -5. The time now is 08:29 AM.