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

link|improve this question

0% accept rate
Why did sudo not work? What errors you get? – Zoredache Jan 11 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 at 7:11
feedback

2 Answers

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
link|improve this answer
I will try ssh. – valpa Jan 11 at 7:14
Your other option may be to do something with expect. – Zoredache Jan 11 at 7:25
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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