Help - Search - Members - Calendar
Full Version: Startup Scripts And Su
Linuxhelp > Support > Technical Support
jdklusman
Im writing a start-up script that trys to su to a non superuser account to start a screen for a program (mutella) and then detaches the screen. Im running into trouble. Heres my code for it that is relevant to the issue.

M_USER="jd"
DIR=/usr/local/bin

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=$DIR/mutella
NAME=Mutella
DESC="P2P Client"
case "$1" in
start)
if [ -e $DIR ];
then
echo "Starting $DESC: $NAME"
cd $DIR
su $M_USER -c `screen -d -m -S $NAME $DAEMON`
else echo "No such directory: $DIR"
fi
;;
esac
exit 0

When i execute this Mutella starts fine, but i can not reattach the screen as root (because the screen belongs to JD account) and when i su to JD and issue the screen -R or even screen -r Mutella it tells me im not the owner of the screen.

Any help would be gratefull, also been searching for a site dedicated to coding linux scripts any links?
hughesjr
In a bash / sh script .... the things surrounded by `` execute at the command line and then return the results to the script ... I think you want to use " or ' instead of ` for the script.

Second thing is that if you want to get all the environment variables for the user jd, you need to use :

su - jd -c "commands"

instead of:

su jd -c "commands"
-------------------------
So, try this:

{but first, with the process running, see who the owner is with the command:
ps -ef | grep screen
}

su - $M_USER -c "screen -d -m -S $NAME $DAEMON"

then do the command:
ps -ef | grep screen

and see who the owner is....
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.