http://qs1969.pair.com?node_id=600124

perlknight has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks before I head down this path, I would like to know if it is do-able? Could I use Expect to log into a remote host, and sudo as root to run remote command? The environment I am currently at, does not allow you to log in directly as root. Any thoughts? Thanks.

Replies are listed 'Best First'.
Re: Double Expect Whamy...
by Fletch (Bishop) on Feb 15, 2007 at 04:31 UTC

    There's certainly no technical reason it shouldn't work, but keep in mind in order to do that you'd still possibly need to provide a password to sudo on the other side (depending on its configuration). You'd probably want to prompt the local side and send it across, or talk to the sysadmin and get them to allow you to run the one command NOPASSWD: in sudoers.

Re: Double Expect Whamy...
by dsheroh (Monsignor) on Feb 15, 2007 at 15:41 UTC
    Yes, it works fine. I've done it before and it's not overly complicated, although I can't provide code as it's been half a year since my contract with that client expired and I've forgotten most of what I knew about Expect in that time. If you know Expect, it's pretty straightforward. If you don't know Expect, it shouldn't take more than a couple hours (if that) of poking around PerlMonks to get up to speed, and then it's pretty straightforward.