Home > Archive > PERL Beginners > March 2007 > Telnet question in Perl
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Telnet question in Perl
|
|
| Don Dukelow 2007-03-26, 6:58 pm |
| I'm using Net::Telnet in my Perl script and I can get through the user
login ok. But when I try to "sudo" to root I can't get there. Any
ideas?
My $TELNET =3D Net::Telnet->new(Timeout =3D> 10,
Prompt =3D> "/$prompt/",
Errmode =3D> 'return',
Host =3D> "$host");
$TELNET->login($LOGIN, $PASSWD); # I can get this far ok and do
commands
$TELNET->('sudo su -');
$TELNET->waitfor('/Password/');
$TELNET->print("$PASSWD");
$TELNET->waitfor('/root/'); #I get a pattern match time out
on this line
I've tried single and double quote as well as no quote. Can' get past
it.
Don Dukelow
| |
|
| simplest questions first...
is "sudo" a valid command on that particular system?
if so, is "sudo su -" a valid syntax in that environment?
is "/Password/" a valid prompt being returned by that system?
should the "/"s be a part of the prompt text?
i've never included "/"s in my expected returns unless they were part of the
text i expected to see, though this could well be a viable format i've never
before seen.
On 3/26/07, Dukelow, Don <don.dukelow@hp.com> wrote:
>
> I'm using Net::Telnet in my Perl script and I can get through the user
> login ok. But when I try to "sudo" to root I can't get there. Any
> ideas?
>
> My $TELNET = Net::Telnet->new(Timeout => 10,
> Prompt => "/$prompt/",
> Errmode => 'return',
> Host => "$host");
>
> $TELNET->login($LOGIN, $PASSWD); # I can get this far ok and do
> commands
>
> $TELNET->('sudo su -');
> $TELNET->waitfor('/Password/');
> $TELNET->print("$PASSWD");
> $TELNET->waitfor('/root/'); #I get a pattern match time out
> on this line
>
> I've tried single and double quote as well as no quote. Can' get past
> it.
>
> Don Dukelow
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
--
since this is a gmail account, please verify the mailing list is included in
the reply to addresses
| |
|
| the "/"s i was referring to are in your 'waitfor' texts -
Password shows '/Password/' rather than 'Password' ->
waitfor('/Password/')
root shows '/root/' rather than 'root' -> waitfor('/root/')
if that doesn't point to the problem, i can't help any further. hopefully
someone else can.
On 3/26/07, Dukelow, Don <don.dukelow@hp.com> wrote:
>
> Yes I can manualy sudo using the format shown all the time. What is
> returned is Password: sorry about the collen when I do it manualy. As
> for the "/"s I'm not sure which one you mean but I was tring all kinds
> of thinks to get it to work. That is just what I ended up with.
>
> Don Dukelow
>
> -----Original Message-----
> From: jm [mailto:jm5379@gmail.com]
> Sent: Monday, March 26, 2007 4:22 PM
> To: beginners@perl.org
> Subject: Re: Telnet question in Perl
>
> simplest questions first...
> is "sudo" a valid command on that particular system?
> if so, is "sudo su -" a valid syntax in that environment?
>
> is "/Password/" a valid prompt being returned by that system?
> should the "/"s be a part of the prompt text?
>
> i've never included "/"s in my expected returns unless they were part of
> the text i expected to see, though this could well be a viable format
> i've never before seen.
>
>
> On 3/26/07, Dukelow, Don <don.dukelow@hp.com> wrote:
>
> out
>
>
>
> --
> since this is a gmail account, please verify the mailing list is
> included in the reply to addresses
>
--
since this is a gmail account, please verify the mailing list is included in
the reply to addresses
| |
|
| i can't find any reference to a "cmw" option so i'll assume that's a typo
for "cmd".
is the typo only in the email or also in your script?
beyond that, the only difference i see between your script and the
net::telnet documentation is your use of single-quotes rather than
double-quotes around the uname argument. since you're not passing variables
i wouldn't think that would matter but you might try double-quotes and see.
i've always used double-quotes without any problem, but i've never used the
cmd option so i'm not familiar with any quirks specific to that part.
On 3/27/07, Dukelow, Don <don.dukelow@hp.com> wrote:
>
> Thank you Jim for your help, hopefully I'll be able to keep it streat.
>
> Now I have another problem once I get sudo to root commands like
>
> My @VENDER = $TELNET->cmw('uname');
> Print "@VENDER\n";
>
> Don't work where as they did when I was just loged in as myself. The
> Input_log file says the command was exicuted but the array didn't pick
> it up.
>
> Don Dukelow
>
> -----Original Message-----
> From: jm [mailto:jm5379@gmail.com]
> Sent: Monday, March 26, 2007 5:13 PM
> To: beginners@perl.org
> Subject: Re: Telnet question in Perl
>
> the "/"s i was referring to are in your 'waitfor' texts -
> Password shows '/Password/' rather than 'Password' ->
> waitfor('/Password/')
> root shows '/root/' rather than 'root' -> waitfor('/root/')
>
> if that doesn't point to the problem, i can't help any further.
> hopefully someone else can.
>
>
> On 3/26/07, Dukelow, Don <don.dukelow@hp.com> wrote:
>
>
| |
|
| then i've exhausted my "expertise". the best i can offer now is good luck.
anyone else have something better to offer?
On 3/27/07, Dukelow, Don <don.dukelow@hp.com> wrote:
>
> The cmd typo was only in my e-mail, but I've tried both single and
> double-quotes. It make no difference! Its only after I sudo to root
> thaat I have this problem.
>
> Don Dukelow
>
> -----Original Message-----
> From: jm [mailto:jm5379@gmail.com]
> Sent: Tuesday, March 27, 2007 12:01 PM
> To: Beginners List
> Subject: Re: Telnet question in Perl
>
> i can't find any reference to a "cmw" option so i'll assume that's a
> typo for "cmd".
>
> is the typo only in the email or also in your script?
> beyond that, the only difference i see between your script and the
> net::telnet documentation is your use of single-quotes rather than
> double-quotes around the uname argument. since you're not passing
> variables i wouldn't think that would matter but you might try
> double-quotes and see.
>
> i've always used double-quotes without any problem, but i've never used
> the cmd option so i'm not familiar with any quirks specific to that
> part.
>
>
> On 3/27/07, Dukelow, Don <don.dukelow@hp.com> wrote:
>
>
>
--
since this is a gmail account, please verify the mailing list is included in
the reply to addresses
| |
| Tom Phoenix 2007-03-27, 10:01 pm |
| On 3/26/07, Dukelow, Don <don.dukelow@hp.com> wrote:
> I'm using Net::Telnet in my Perl script and I can get through the user
> login ok. But when I try to "sudo" to root I can't get there. Any
> ideas?
It might be that sudo is (mis-)configured not to allow you root
access. But I suspect you've just got a bug. Have you tried the
suggestions in the Debugging section of the Net::Telnet docs?
--Tom Phoenix
Stonehenge Perl Training
|
|
|
|
|