Skip to content

Instantly share code, notes, and snippets.

@aero
Forked from krimdomu/gist:6080102
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aero/5cbb4823180bf1bb9438 to your computer and use it in GitHub Desktop.
Save aero/5cbb4823180bf1bb9438 to your computer and use it in GitHub Desktop.
Rex(Net::OpenSSH) and Expect, http://modules.rexify.org/module/Rex::Commands::Expect 도 참고
# Rexfile
use Expect;
set connection => "OpenSSH";
my $expect_timeout = 5;
my $git_password = 'f00b4r';
my $sudo_password = 'test';
task doit => "192.168.122.102" => sub {
my $ssh = Rex::get_current_connection()->{conn};
my ($pty, $pid) = $ssh->open2pty("sudo -p 'sudopass:' -u bert sh -c 'cd /tmp ; git pull'")
my $expect = Expect->init($pty);
$exp->expect($expect_timeout,
[
qr/sudopass:/ => sub { # this is sudo password question
my $exp = shift;
$exp->send("$sudo_password\n");
exp_continue;
}
],
[
qr/passphrase:/ => sub { # this is git password question
my $exp = shift;
$exp->send("$git_password\n");
exp_continue;
}
],
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment