On Tue, Jan 25, 2011 at 10:38:49AM -0600, lee latham wrote: > Thanks for the response, Brett! > > No, I do not have root access or the ability to change the > infrastructure I'm working under. > > I figured I'd pass the sudo password as an argument to the script. > > But can it be done?
I wrote a test bash script that worked: #/bin/sh sudo -S ls<<END y0urP@ssword END ##-- end of script You may need to do a wrapper sudo script and have your actual work in another script; I don't immediately know if passing a stream of commands to sudo would necessarily be what you wanted to do: #/bin/sh sudo -S ./realscript.sh<<END # realscript.sh contains the real work y0urP@ssword END ##-- end of script I suppose you could simply chmod to 700 or 600 and issue 'sh ./yoursudoscript.sh' via ssh. Ultimately, the issue protecting your password. Hope that helps.. Brett > > On Tue, Jan 25, 2011 at 10:18 AM, B. Estrade <[email protected]> wrote: > > 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 > >> [email protected] > >> http://mail.pm.org/mailman/listinfo/houston > >> Website: http://houston.pm.org/ > > > > -- > > B. Estrade <[email protected]> > > _______________________________________________ > > Houston mailing list > > [email protected] > > http://mail.pm.org/mailman/listinfo/houston > > Website: http://houston.pm.org/ > > > _______________________________________________ > Houston mailing list > [email protected] > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ -- B. Estrade <[email protected]> _______________________________________________ Houston mailing list [email protected] http://mail.pm.org/mailman/listinfo/houston Website: http://houston.pm.org/
