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
In reply to Perl expect : send command executing multiple times by ryalagikar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |