I am trying to connect to switch which is signaling point switch.
I need to execute the below commands to get to login terminal.
- telnet IP Port
- Send CTRL+A
- Get Prompt ">"
- Send command login:uid=user.
- Requests for Password provide password.
- Gets terminal ">"
Then I have to continue executing some commands to go further, but my problem I am facing an issue while sending CTRL+A.
When I send "ctrl+A" using Expect it just prints "^A" and waits doesn't provide me the terminal.
So, I modified the script by changing the command to "ctrl+A\n" which gives me the terminal but with new line on my next terminal prompt.
Like the below output:
^A
^A
^A
>
wait's here at next line.
which fails to match my next command regular expression ">" and doesn't send the login name.
Can somebody tell me why my first command "^A" fails to get me terminal? And why the command was executed three times before I get the terminal?
I manual scenario it works fine for single ctrl+A
My Sample code:
use Expect;
my $exp = Expect->spawn("telnet 10.10.1.35 2020");
$exp->expect($timeout,
[ qr/]'./ => sub {my $exp = shift;
$exp->send("\cA\n");
} ]
);
$exp->expect($timeout,
[ qr/>/ => sub { my $exp = shift;
$exp->send("login:uid=user\n");
} ]
);
$exp->expect($timeout,
[ qr/Enter Password :/ => sub { my $exp = shift;
$exp->send("xxx\n");
} ]
);
Thank you, Pradeep.
$exp->send(chr(1));to send a Ctrl-A - glenn jackman