file: test.sh
who
su superuser <<BELUGA
mysuperpassword
BELUGA
who
$ ./test.sh
just waits for input. What am I doing wrong? Is there a way to automate this?
|
feedback
|
|
You want to use the "expect" command for passing your username and password. Note however that what you want to do there smells like a bad approach. Maybe we can halp you better if you elaborate a little more on your original problme you want to solve. | ||||
|
feedback
|
|
I think it would be a lot better to install/use sudo an with a configuration config that allows NOPASSWD for the specific action you are trying to automate. It will be much safer to allow a specific command via sudo then it would be to store your root password in a text file somewhere. | |||||||||||
feedback
|
|
Running a script as a user and having it upgrade its permissions to root is probably a bad idea. A better solution would be to run the script as root and have it downgrade its permissions as necessary:
When run as root (assuming
However if you really want to have a script run as a user and be able to execute commands as root, there are 2 options that I know of.
| ||||
|
feedback
|
su'd command.) – grawity Mar 24 '10 at 18:10