Created
July 25, 2013 14:15
-
-
Save krimdomu/6080102 to your computer and use it in GitHub Desktop.
rex and expect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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