Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.