doubts in using net::telnet in perl

Hi,

I am using Net::Telnet module to login to a remote machine and to
perform a series of steps. In my script i am calling a shell script
which does some operations and takes almost 3 min to complete. I want
to redirect the output of that script to the console in run time, when
it is running. Is there any way to do this?

code
=====
$t = new Net::Telnet(Timeout => 180, Output_log => "$my_loc/my_op");
$t->open($my_machine);
$t->login($username, $passwd);
.....
.....
.....
print $t->cmd("$my_loc/my_shell.csh") // It prints the output
after execution.
$t->close();

Pls help me.


--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Sooraj S [ Di, 20 Juli 2010 16:57 ] [ ID #2044885 ]

Re: doubts in using net::telnet in perl

On Tue, Jul 20, 2010 at 10:57, Sooraj S <soorajspadmanabhan [at] gmail.com> wrot=
e:
> Hi,
>
> I am using Net::Telnet module to login to a remote machine and to
> perform a series of steps. In my script i am calling a shell script
> which does some operations and takes almost 3 min to complete. I want
> to redirect the output of that script to the console in run time, when
> it is running. Is there any way to do this?
>
> code
> =3D=3D=3D=3D=3D
> $t =3D new Net::Telnet(Timeout =3D> 180, Output_log =3D> "$my_loc/my_op")=
;
> $t->open($my_machine);
> $t->login($username, $passwd);
> ....
> ....
> ....
> print $t->cmd("$my_loc/my_shell.csh") =C2=A0 =C2=A0 // It prints the outp=
ut
> after execution.
> $t->close();

If you say

$t->dump_log(\*STDOUT); before you call $t->cmd(), then everything
that would have been written to the telnet screen will be written to
the standard output.


--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
chas.owens [ Mi, 21 Juli 2010 15:42 ] [ ID #2044892 ]

Re: doubts in using net::telnet in perl

Hi Chas Owens,

Thanks for your reply. I tried as you suggested. It prints the output
in the run time but the output is unformatted.

< 0x00000: 77 6f 72 6b 2f 61 74 6c 61 6e 74 69 63 5f 6e 6f home/
shell_script
< 0x00010: 72 5f 72 65 6c 65 61 73 65 2e 63 73 68 5f 74 65
_newlone.csh_te
< 0x00020: 73 74 0d 0a 0d 0a 47 6f 6c 64 65 6e 20 4a 46 46
st....Mounted File
< 0x00030: 53 32 20 3d 20 76 65 6e 74 6c 6e 78 30 2d 6e 6f system
= xxdper12
......
......
.......


It should actually print like

home/shell_script_newlone.csh_test....
Mounted Filesystem = xxdper12

Is there any way to avoid the address values that gets attached to the
actual output..


--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Sooraj S [ Mi, 21 Juli 2010 16:41 ] [ ID #2044894 ]

Re: doubts in using net::telnet in perl

On Wed, Jul 21, 2010 at 10:41, Sooraj S <soorajspadmanabhan [at] gmail.com> wrote:
> Hi Chas Owens,
>
> Thanks for your reply. I tried as you suggested. It prints the output
> in the run time but the output is unformatted.
snip
>
> Is there any way to avoid the address values that gets attached to the
> actual output..
snip

Hmm, it looks like you need $t->output_log(\*STDOUT) not $t->dump_log(\*STDOUT).


--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
chas.owens [ Mi, 21 Juli 2010 17:06 ] [ ID #2044895 ]

Re: doubts in using net::telnet in perl

Thanks for your help...It worked...My shell script prints properly...

At one stage it will prompt for user input
------------------------------------------
Mountpoint : Xpr23filesystem
Kernel : verified
P2P : katren"
OK to go : [y/n] ?
--------------------------------------

How to get the user input...? (shell sctipt is called in my main code
as shown in my first mail)


--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Sooraj S [ Do, 22 Juli 2010 09:38 ] [ ID #2044984 ]

Re: doubts in using net::telnet in perl

On Thu, Jul 22, 2010 at 03:38, Sooraj S <soorajspadmanabhan [at] gmail.com> wrote:
> Thanks for your help...It worked...My shell script prints properly...
>
> At one stage it will prompt for user input
> ------------------------------------------
> Mountpoint : Xpr23filesystem
> Kernel : verified
> P2P : katren"
> OK to go : [y/n] ?
> --------------------------------------
>
> How to get the user input...? (shell sctipt is called in my main code
> as shown in my first mail)
snip

If you need to interact with the shell or with programs you can use
the cmd method. You will need to use lower level methods that let you
watch for content:

# type the command and hit enter
$t->print("$my_loc/my_shell.csh");
# wait for the program to reach the [y/n] prompt
$t->waitfor('^OK to go : \[y/n] \?');
# do this if you want it to be interactive
#my $choice = <STDIN>;
#$t->print($choice);
# or you can just send the same choice every time
$t->print("y");

You will need to use the put method instead of the print method if the
program does not require you to hit enter after typing y or n.


--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
chas.owens [ Do, 22 Juli 2010 14:51 ] [ ID #2044985 ]
Perl » gmane.comp.lang.perl.beginners » doubts in using net::telnet in perl

Vorheriges Thema: Example code for storing picture in MySQL DB
Nächstes Thema: Perl 6 soon?