0

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

valpa
  • 319
  • 9
  • 15
  • Why did sudo not work? What errors you get? – Zoredache Jan 11 '12 at 05: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 07:11

2 Answers2

1

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
Zoredache
  • 130,897
  • 41
  • 276
  • 420
0

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.

theist
  • 1,229
  • 2
  • 10
  • 24