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