I need to a script that telnet to eagle STP device and run commands there.
When I try to telnet a eagle STP device from command prompt,
I am getting the below output :
[root@localhost tmp]# telnet hostname port
Trying hostname...
Connected to hostname hostname).
Escape character is '^]'.
I am not getting any prompt here to match in the perl script. We need to press control+a inorder to get the prompt.If we press control+a, it will give the below output
[root@localhost tmp]# telnet hostname port
Trying...
Connected to hostname.
Escape character is '^]'.
>
Then we need to enter login:uid at this prompt
> login:uid=dumps
Then it prompts for a password
Enter password : password
then again we need to press control+a again to execute the commands.
> rtrv-dstn.
I am struck here , I am unable to pass control+a command after telnet command.
I wrote the script in the below way. But it is not working. Can ANY ONE HELP ME !!!!
#!/usr/bin/perl
use Net::Telnet;
my $host='hostname';
my $port='port';
my $telnet = new Net::Telnet(Host => $host, Port => $port, Timeout => 20)
or die "connect failed: $!";
$telnet->open($host);
print"Hi iii";
$telnet->waitfor('+$/i');');
print"Hello";
$telnet->print("^]");
$telnet->waitfor('/>$/i');
$telnet->print("login:uid=username");
$telnet->waitfor('/Enter Password :\s+$/i');
$telnet->print("password");
$telnet->waitfor('/>$/i');
@res1=$telnet->print("rtrv-dstn");
print"@res1";
Exit;
From Net::Telnet:
print - write to object
This method writes
@listfollowed by the output record separator to the open object and returns 1 if all data was successfully written. On time-out or other failures, the error mode action is performed. See errmode().
You can set the output_record_separtor via $telnet->ors("\x01"); or by using:
$telnet->cmd("\x01");
to send a Ctrl-A when you need it. Don't have an Eagle STP for testing, but I hope this helps.
By the way, you should always check the output of each method call to make sure it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With