Change the net:telnet prompt durring runtime.

  • Thread starter peter_de_groot_1966
  • Start date
P

peter_de_groot_1966

Hi all,

I have a problem with changing the telnet prompt durring runtime.
My program has to connect to for me at the writing unknow unix machines
with command prompts not know to me.
To be able todo this I tought in updating the telnet prompt by reading
a value from a file and then changing the prompt.

My standard setting for the prompt is

my $unix_cmd_prompt = '/[\$%#>:=]\s?$|term/i';

I then add to the prompt with the sub
add_system_prompt();

sub add_system_prompt
{
my $customerprompt;
my $promptfile = "custprompt.txt";
if(-e $promptfile) {
open(FH,"<$promptfile");
while (defined ($customerprompt = <FH>)) {
chomp $customerprompt;
$customerprompt =~ s/^\s+//;
if (length($customerprompt) gt 0) {
$unix_cmd_prompt = $unix_cmd_prompt.'|'.$customerprompt;
}
}
close(FH);
}
}

and then set the prompt

$t->prompt($unix_cmd_prompt);

and offcourse I first devine the $t

my $t = new Net::Telnet (
Timeout => 240,
Cmd_remove_mode => 0,
Errmode => \&whinge,
Output_record_separator => '',
#Dump_log => 'dump.txt',
);

The login works fine until I add something to the prompt via the
add_system_prompt adds something to the prompt.

The documentation for net:telnet states that you have to single quote
the regular expression.

Is this where my problem is and if so what is the way around this
 
P

peter_de_groot_1966

Hi all,

I have a problem with changing the telnet prompt durring runtime.
My program has to connect to for me at the writing unknow unix machines
with command prompts not know to me.
To be able todo this I tought in updating the telnet prompt by reading
a value from a file and then changing the prompt.

My standard setting for the prompt is

my $unix_cmd_prompt = '/[\$%#>:=]\s?$|term/i';

I then add to the prompt with the sub
add_system_prompt();

sub add_system_prompt
{
my $customerprompt;
my $promptfile = "custprompt.txt";
if(-e $promptfile) {
open(FH,"<$promptfile");
while (defined ($customerprompt = <FH>)) {
chomp $customerprompt;
$customerprompt =~ s/^\s+//;
if (length($customerprompt) gt 0) {
$unix_cmd_prompt = $unix_cmd_prompt.'|'.$customerprompt;
}
}
close(FH);
}
}

and then set the prompt

$t->prompt($unix_cmd_prompt);

and offcourse I first devine the $t

my $t = new Net::Telnet (
Timeout => 240,
Cmd_remove_mode => 0,
Errmode => \&whinge,
Output_record_separator => '',
#Dump_log => 'dump.txt',
);

The login works fine until I add something to the prompt via the
add_system_prompt adds something to the prompt.

The documentation for net:telnet states that you have to single quote
the regular expression.

Is this where my problem is and if so what is the way around this


The problem had nothing to do with the quotes.

The orignal prompt ends on /i and my add routine added at the end of
this which makes the regular expression worng.

So in the new routine i fist delete /i then add the needed prompt(s)
and add /i

This now works
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top