Hi All
I am using perl expect module in our legacy application to scp some file to othe machine. The password for the client machine changes every 15 days, so we can't use ssh public keys.
For most of the machine the Expect script as expected, but for some the the prompt of the machine appears after the perl expect part code is excecuted.
Here is the code of the script.
$Expect::Exp_Internal = 1;
my $exp = Expect->new();
#$exp->log_stdout(1);
$exp->spawn("scp test\.txt foo\@bar:/tmp/test\.txt ") or warn("Unable
+ to spwan : $!");
$exp->expect(9,
[ qr/Are you sure you want to continue connecting \(yes\/
+no\)\?/i,
sub { my $self = shift;
$self->send("yes\n");
exp_continue; }],
[ qr/password:/i, sub { my $self = shift;
$self->send("$passwd\n");
exp_continue; }]) or warn("error : " .$exp->
+exp_error());
Here is the output of the script.
Spawned 'scp test.txt foo@bar:/tmp/test.txt '
spawn id(6)
Pid: 17288
Tty: /dev/pts/1
Expect::spawn('Expect=GLOB(0x87a04a8)','scp test.txt foo@bar:
+/tmp/test.txt co...') called at ...
main::foo_project('ARRAY(0x8166e00)') called at .....
Starting EXPECT pattern matching...
Expect::expect('Expect=GLOB(0x87a04a8)',9,'ARRAY(0x89e0d04)','
+ARRAY(0x89e8748)') called at ...
main::foo_project_project('ARRAY(0x8166e00)') called at ....
spawn id(6): list of patterns:
#1: -re `(?i-xsm:Are you sure you want to continue connecting \(yes/
+no\)\?)'
#2: -re `(?i-xsm:password:)'
spawn id(6): Does `'
match:
pattern #1: -re `(?i-xsm:Are you sure you want to continue connectin
+g \(yes/no\)\?)'? No.
pattern #2: -re `(?i-xsm:password:)'? No.
Waiting for new data (9 seconds)...
TIMEOUT
Returning from expect with TIMEOUT or EOF
error : 1:TIMEOUT at ....
foo@bar's password:
Any help in this regard will be appreciated or is there any other way to achieve the same?
stackoverflow link