[pm-h] Automating sudo/bash terminal

B. Estrade estrabd at gmail.com
Tue Jan 25 08:18:13 PST 2011


On Tue, Jan 25, 2011 at 10:17:31AM -0600, lee latham wrote:
> 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!

Your biggest issue is going to be maintaining security. Sounds like
you either have to store the password somewhere or allow certain
commands to be executed via sudo unencombered via password.

Do you have root on this box?

And I hate to give you the typical "Perlish" response, but what
exactly are you trying to do? I would imagine that if you've painted
yourself into a corner where you have to issue sudo in batch process,
there are like better solutions to what you're needing to accomplish.

Cheers,
Brett

> 
> Best,
> Lee
> _______________________________________________
> Houston mailing list
> Houston at pm.org
> http://mail.pm.org/mailman/listinfo/houston
> Website: http://houston.pm.org/

-- 
B. Estrade <estrabd at gmail.com>


More information about the Houston mailing list