TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:10172] Perl newbie - starting a telnet process...



Troy Johnson wrote:
> 
> Is there an expect perl package on CPAN somewhere?

As far as I know there isn't such a package. (yet). Expect is TCL based
and very different that perl. What I have done in the past is to call
small expect scripts from my 'main' perl scripts. I get the best of both
worlds.

> 
> Clay Fandre wrote:
> >
> > I would recommend using expect. It is easier to use (in this particular
> > case) and is much nicer about timeouts and stuff like that. It also
> > comes with autoexpect, which automatically creates an expect script for
> > you. Very nice.
> >
> > As far as your perl script goes, you are grabbing the output of the
> > telnet command instead of inputting to it. To input, the pipe goes after
> > the command:
> > open( TELNETPROC, "telnet|") || die "Unable to open telnet $!\n";
> >
> > (do a perldoc -f open for more info)
> >
> > open only allows for one way or the other. (Input or output.) That's why
> > I recommend expect. If you really need to use perl, look at open2, which
> > allows for 2-way communication to your process. (I'm not sure if it is
> > installed by default. Might have to install it from CPAN.)
> >
> > Mike Glaser wrote:
> > >
> > > I was trying to write a Perl script today that would telnet into a
> > > router, issue a few commands and then close. I wasn't having any
> > > luck. Can anyone tell me how to go about doing it?? Here are the
> > > particulars...
> > >
> > > 1) telnet
> > > 2) open xxx.xxx.xxx.xxx
> > > 3) enter_password
> > > 4) command
> > > 5) exit
> > >
> > > Here is what my script was looking like...
> > >
> > > #!/usr/bin/perl
> > > open( TELNETPROC, "|telnet");
> > > print TELNETPROC "open 192.168.0.1\n";
> > > print TELNETPROC "thesecretpassword\n";
> > > print TELNETPROC "clear line 1\n";
> > > print TELNETPROC "exit\n";
> > > close FTPPROC;
> > >
> > > What may I be missing here?? I have the O'Reilly book 'Learing Perl'
> > > to help me get started with Perl, but I have not been able to pick up
> > > much yet.
> > >
> > > Thanks,
> > > Mike Glaser
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> > > For additional commands, e-mail: tclug-list-help@mn-linux.org
> >
> > --
> > Clay Fandre
> > cfandre@maddog.mn-linux.org
> > Twin Cities Linux Users Group
> > http://www.mn-linux.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> > For additional commands, e-mail: tclug-list-help@mn-linux.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> For additional commands, e-mail: tclug-list-help@mn-linux.org

-- 
Clay Fandre
cfandre@maddog.mn-linux.org
Twin Cities Linux Users Group
http://www.mn-linux.org