Questions tagged [expect.pm]

Expect.pm - Expect for Perl

Expect.pm is built to either spawn a process or take an existing filehandle and interact with it such that normally interactive tasks can be done without operator assistance. This concept makes more sense if you are already familiar with the versatile Tcl version of Expect.

30 questions
5
votes
1 answer

Using expect in Perl, how to add options of ignoring case with method $object->expect()?

This is example found in perldoc: $object->expect(15, '-re', "$str"); I want to add option 'i' to the match. This won't work: $object->expect(15, '-re', qr/$str/i); Do I have to use this format: $exp->expect($timeout, [ qr/$str/i, sub {}],…
Jay Zhou
  • 51
  • 1
4
votes
1 answer

Spawn Expect from a perl thread

I am working on a script which needs to spawn an Expect process periodically (every 5 mins) to do some work. Below is the code that I have that spawns an Expect process and does some work. The main process of the script is doing some other work at…
comatose
  • 1,952
  • 7
  • 26
  • 42
4
votes
1 answer

Automate and capture login prompt through perl's expect

I'm trying to automate a login prompt in Perl I'm using SSHGetCredentials('login_prompt' => 1) to generate a login prompt which is a function of perl's Expect::SSH library This is how my code looks like, here REST::Client->getCredentials()…
Bad_Coder
  • 1,019
  • 1
  • 20
  • 38
3
votes
1 answer

How do you properly wait for the prompt in the terminal before sending a command using expect for perl?

I'm very new to both Perl and expect and have been trying to figure out how to send a command when only the prompt appears. I know how to send a command after a certain output is displayed in the terminal, but can't find the correct way to send a…
MattieG4
  • 150
  • 2
  • 12
3
votes
1 answer

Perl ssh Password

I am trying to use perl to SSH in to a machine and issue a few commands... my $ssh = Net::SSH::Perl->new($host); $ssh->login($user,$pass); my($stdout, $sterr, $exit) = $ssh->cmd($cmd); print "$stdout \n" This is the general idea, but I am still…
Tom
  • 312
  • 5
  • 17
2
votes
1 answer

Waiting on expect - until spawned program completes

I'm trying to use expect to spawn a program in an automation script in perl. And I'm trying to decide how to wait on expect for this program to finish, since - I can't rely on any string matching as the program is not consistent with how it…
seek
  • 41
  • 3
2
votes
1 answer

Perl expect doesn't work after logout

A very simple code to connect to a server, run some commands, disconnect and run some more commands locally. #!/usr/bin/perl use strict; use warnings; use Expect; my $timeout = 15; my $password = "1234"; my $expect = new…
NPS
  • 6,003
  • 11
  • 53
  • 90
2
votes
1 answer

Get the output of a command executed via $self->send() on a remote host in Perl Expect module

I am using Expect module in Perl to do an interactive activity and execute a command on a remote machine. Request your help on this Here are the steps I used Do a switch user to another account. Sends the password to login. Once I get the shell…
Joseph
  • 41
  • 4
1
vote
1 answer

Attempting to access Expect object inside of Net::SSH::Expect gives an ERROR

Perl: attempting to access Expect object inside of Net::SSH::Expect gives an ERROR. Example pseudo code: my $m = Net::SSH::Expect->new( host => 192.168.1.6, user => 'root', password => 'password', …
ZaPaDoS
  • 13
  • 4
1
vote
1 answer

Expect.pm:expect() gives "Unexpected Subroutine" error

I'm extremely new to Perl and struggling with something. Recently, another developer left my company, and my boss has asked me to fix a Perl script that my former colleague wrote but did not document. This script worked great in the past. I…
Pete
  • 1,511
  • 2
  • 26
  • 49
1
vote
1 answer

how to check if the Expect->spawn($command) is success?

I am passing an scp command in Expect->spawn($command), I am also passing the password or password + OTP based on a $object->expect(). Could you let me know if there is a way to determine if the command has been run successfully ? I'm trying…
tourist
  • 506
  • 1
  • 6
  • 20
1
vote
0 answers

Perl Expect: For ssh login, if a bad password fails, how to try another password?

When using Expect in Perl to automate ssh logins, if the 1st password fails, how can we try another password? It's not hard to find the pure Expect examples to do so but cannot find one for Expect in Perl. use Expect; my $bad_pwd = 'pw123'; my…
Steve
  • 337
  • 1
  • 4
  • 13
1
vote
1 answer

Not able to execute command in remote machine Using Net::SSH::Expect

I wanted to make the remote connection and automate the change password of any user account in that remote machine so I am using Perl Net::SSH:: Expect module. My connection is happening but I'm not able to perform any command on the remote machine.…
luffy008
  • 37
  • 7
1
vote
0 answers

Expect.pm send trims the number sign

I'm trying to use Expect.pm on an old machine with perl 5.8.8. It works but when I send a text that contains a "#" sign it is removed from the text. Is there a way to escape/protect it? Thanks Sorry corrected it is 5.8.8 #!/usr/bin/perl use…
user1708042
  • 1,740
  • 17
  • 20
1
vote
0 answers

Ssh using expect with threads?

Have you found solution any on how to ssh using expect with threads? sub thDoWork { #variables my $thread_number = $_[0]; my $PassStoreQueue = $_[1]; my $Thread_Die = ''; my $My_Print_Bucket = ''; while ($Thread_Die ne…
1
2