Created
September 19, 2018 06:40
-
-
Save Abhinickz/c6fa508ea5883a5930bbb67330492a68 to your computer and use it in GitHub Desktop.
Sudo start process: when password is required
This file contains 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
#!/usr/bin/perl | |
use strict; use warnings; use Data::Dumper; | |
use Expect; | |
my $expect = Expect->new; | |
my $command = 'sudo service ssh start'; | |
my $timeout = 500; | |
my $password = "password"; | |
$expect->raw_pty(1); | |
$expect->spawn($command) | |
or die "Cannot spawn $command: $!\n"; | |
$expect->expect($timeout, | |
[ qr/password for abhasker/i, #/ | |
sub { | |
my $self = shift; | |
$self->send("$password\n"); | |
exp_continue; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment