Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

startup script as non-root user

Status
Not open for further replies.

denisl

Technical User
Jun 18, 2001
36
US
I have a startup script linked from /etc/init.d to /etc/rc3.d. When the system boots root starts the script and owns the processes. How can I have the script started as a different user?

Thanks.
 
man su

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
When using su I need to pass the script to the su command..

for example..
script1.sh:
su nonroot "script2.sh"

script2.sh
touch nonrootfile

Is there a way I can run script2.sh without calling it from script1.sh? The startup script is a few hundred lines and I don't see how I could pass that to the su command unless I update every line which starts a process with "su nonroot".

I was hoping for a one liner at the top of the script..
 
A starting point:
Code:
#!/bin/ksh
for arg; do args=$args" '$arg'"; done
[ $(id -un) != nonroot ] && exec su nonroot "$0 $args"
# real script here
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Have you looked at the following construct:

su - nonroot -c "/path/to/script2.sh" > /path/to/logfile 2>&1

We use this to start up Oracle databases (from root at system boot) as user oracle.

I hope that helps.

Mike
 
Hi,

You can use here files

Code:
SCRIPT=/some/path/to/file.ksh
su - someuser <<-END
        if [ -f $SCRIPT ]
        then
                . /home/someuser.env
                $SCRIPT
        else
                print "error: $SCRIPT does not exist"
        fi
        exit 0
END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top