Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to have these commands run as the ss user from root

mkdir bin
cp -r /opt/gitolite .
gitolite/install -ln
gitolite setup -pk ss.pub

mkdir -p .gitolite/hooks/common
ln -s /opt/pre-receive .gitolite/hooks/common/

so everything is executed in /home/ss. The 4th line requires $HOME/bin as you can see from the 3rd line.

The only way I can get it to work is by adding su -c "command" ss to each line, which is not a nice hack.

This is an extension to my previous question, where I wasn't precise enough.

Question

How do I run all these commands as a script in a practical way?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Why don't you make it an actual executable script and call the script while running as the other user via su

share|improve this answer

A shell script is exactly that, a shell script. Meaning that not only can you run normal shell commands, but you can also execute the built-ins for whatever shell you're using. We could slightly modify your script thusly to have all the commands run as if in the home directory of whatever user runs this script.

#!/bin/bash

cd $HOME
mkdir bin
cp -r /opt/gitolite .
gitolite/install -ln
gitolite setup -pk ss.pub

mkdir -p .gitolite/hooks/common
ln -s /opt/pre-receive .gitolite/hooks/common/
share|improve this answer
1  
WHERE IS THE SHEBANG, YOU SAVAGE. –  MDMarra Nov 2 '12 at 2:22
1  
@MDMarra: In related news, after typing in the shebang line I hit <ESC>: before realizing what I was doing. Talk about muscle memory. –  Scott Pack Nov 2 '12 at 2:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.