Skip to content

Instantly share code, notes, and snippets.

@krimdomu
Created July 25, 2013 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krimdomu/6080102 to your computer and use it in GitHub Desktop.
Save krimdomu/6080102 to your computer and use it in GitHub Desktop.
rex and 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