[pm-h] Automating sudo/bash terminal

lee latham rasto at cm4msaa7.com
Tue Jan 25 08:17:31 PST 2011


Hi Y'all,

I'm having a surprisingly difficult time automating a terminal
session, so I thought I'd see if you guys have any thoughts.

I'm in a situation where I need to issue commands in a sudo
environment.  So I've got to authenticate the sudo, issue commands
after that (this is the part I'm having trouble with), read the output
of the commands and issue new commands based on that output.  So
basically I need to do like 'sudo bash' and then issue commands in
that bash session.

I've tried various tricks to no avail, and I'd really rather avoid
using Expect, as I expect the process to get a little lengthy at
times.

The main problem, for example, is that if I simply execute `sudo
dowhatever` via backticks or system, I still need to authenticate, and
even if I do that then that session is immediately closed.

A similar situation is when using Net::OpenSSH, and I need to, say,
become a different user on the remote machine and issue commands as
that user.

I suspect my unix knowledge is inadequate to even properly
understanding the problem :-)

Any thoughts?  Any input would be greatly appreciated!

Best,
Lee


More information about the Houston mailing list