Possible Duplicate:
Run a shell script as a different user
While writing scripts to automate the intialisation of SVN mirror repositories (svnsync), I again ran into problems trying to start another script with another user's privileges.
#!/bin/sh
# This outer script is always run with root privileges ("sudo create-repo.sh")
# Create repository, set privileges, etc
[...]
# Set up remote mirror; this works fine! (SSH key authentication)
ssh svnsync@anotherserver /var/lib/svn/init-mirror.sh $REPO
# Set up local mirror as "svnsync" user
# ???
How can I call the other script, on the same machine, as a different user? Note that the outer script is always executed as root so su
'ing as anyuser should not be a problem.
I tried something like:
su svnsync; /path/to/init-mirror.sh $REPO; exit
and get weird results. How are you supposed to do it? When it's so easy remotely it's probably possible locally, right? (For now, let's pretend running the outer script as the same "svnsync" user is not an option.)
I think the question title sucks, so please help me reword it if you can.
Duplicate of Run a shell script as a different user . I think you can close it yourself?