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

There are several admin-like accounts in our Linux server, different account for different purpose.

Sometimes, there need multi-account co-work to finish a job. Manually, I can login and type the commands. But How can I make it into a single script (BASH)?

BTW: sudo didn't work on my server

share|improve this question
    
Why did sudo not work? What errors you get? –  Zoredache Jan 11 '12 at 5:37
    
I have no root privilege. So I don't think I can use su. I can su to other account. But sudo will give me an password error message (password correct for su), and I don't know why. ALL account are NIS based, not local. –  valpa Jan 11 '12 at 7:11

2 Answers 2

Your question is a bit unclear. But I believe you are asking how you can run commands that must be performed with other accounts.

Simply do something like this.

#!/bin/bash

# execute blah as username, assuming the main script is running as root
su username -c blah

# execute blah as username, assumes you have delegated calling users permissions to run command as username
sudo -u username blah

# execute blah as username, using key-based authentication.
ssh username@localhost blah
share|improve this answer
    
I will try ssh. –  valpa Jan 11 '12 at 7:14
    
Your other option may be to do something with expect. –  Zoredache Jan 11 '12 at 7:25

You must use su -c command to run commands as another user. It will prompt interactively for the password. If you need to run it in batch mode you can use expect.

share|improve this answer

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.