Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Change the net:telnet prompt durring runtime. (http://www.velocityreviews.com/forums/t891376-change-the-net-telnet-prompt-durring-runtime.html)

peter_de_groot_1966@yahoo.com 03-16-2005 03:33 PM

Change the net:telnet prompt durring runtime.
 
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


peter_de_groot_1966@yahoo.com 03-18-2005 10:01 AM

Re: Change the net:telnet prompt durring runtime.
 

peter_de_groot_1966@yahoo.com wrote:
> 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



All times are GMT. The time now is 06:04 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.