Skip to content

Instantly share code, notes, and snippets.

@Abhinickz
Created September 19, 2018 06:40
Show Gist options
  • Save Abhinickz/c6fa508ea5883a5930bbb67330492a68 to your computer and use it in GitHub Desktop.
Save Abhinickz/c6fa508ea5883a5930bbb67330492a68 to your computer and use it in GitHub Desktop.
Sudo start process: when password is required
#!/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