ryalagikar has asked for the wisdom of the Perl Monks concerning the following question:
I am writing perl-expect script, in script am trying to login to remote machine then sudo su to another user and then execute two commands. Everything is working fine but the first command is executing multiple times.
my $ssh = Net::OpenSSH->new("$user:password\@$host"); $ssh->error and die "Unable to connect $host " . $ssh->error; my ($pty,$pid) = $ssh->open2pty({stderr_to_stdout => 1}, 'sudo su - us +er1') or die "Failed to attempt"; my $expect = Expect->init($pty); $expect->log_file("expect.pm_log", "w"); my $result = $expect->expect(3, ["\[\r\n]?\[^\r\n]+\[%#>\$] \$" ,sub { shift->send("da +te\r"); exp_continue;}], [qr/Day/ , sub { my $self = shift; $self->send("touch +test.txt\r"); $self->soft_close();}] )or die "**** Failed ** ";
Here 'date' command is executing multiple times(2...20times).
Suggestions Please
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl expect : send command executing multiple times
by salva (Canon) on Jul 03, 2015 at 08:15 UTC | |
by ryalagikar (Novice) on Jul 03, 2015 at 08:52 UTC | |
by salva (Canon) on Jul 03, 2015 at 08:55 UTC |