> On Tue, 2002-04-30 at 17:11, Scott wrote:

>> Does anyone know how to make a script to telnet to an IP, authenticate
>> (login / pass) and then reconnect every 8 hours or whenever the connection
>> is lost.
>> 
>> Its rather important because its the only thing stopping me from fully using
>> OSX. I had an applescript that did this with ³MacTelnet² in OS9.
>> 

 
> Since you're running an operating system capable of running perl, I've
> just spent the last hour making this little script for you:

 
> ---START SCRIPT----
> #!/usr/bin/perl
> # v1.0 - May 1, 2002 by Onno Benschop - ITmaze
> # Use this wherever you like, just leave the credit alone.
> #
> # Usage: telnet.pl host user passwd
> #
> # Purpose: keep a telnet connection open
> #
> # Script will connect to host with user and password. As soon
> # as the connection dies, it reconnects. To keep some connections
> # alive longer, it issues an $idleCommand each $idleTime seconds.
> #
> # If you want to just run this in the background, then add & at
> # the end of the command, eg:
> #
> # telnet.pl host user passwd &
> #
> 
> use Net::Telnet;
> $idleCommand = 'date' ; # command to run to keep alive
> $idleTime = 5*60 ; # idle time in seconds
> 
> sub telnet_connect {
> ($host,$user,$passwd)[EMAIL PROTECTED];
> 
> $telnet = new Net::Telnet ( Timeout=>10,
> Errmode=>'return',
> Prompt => '/\$ $/i');
> $telnet->open($host);
> $telnet->login($user, $passwd);
> while () {
> $telnet->cmd($idleCommand) ;
> sleep($idleTime) ;
> }
> }
> 
> sub telnet_use {
> print "Usage: telnet.pl host user passwd\n" ;
> }
> 
> if (!$ARGV[2]) {
> &telnet_use;
> } else {
> while () {
> &telnet_connect ;
> }
> }
> ----END SCRIPT----

 
> You will need to download the Net::Telnet perl module from cpan. The
> manual is here:
> <http://www.perldoc.com/cpan/Net/Telnet.html>
> 
> The software is here:
> <http://www.perl.com/CPAN-local/authors/id/J/JR/JROGERS/>
> 
> Save the script in a file called telnet.pl, then do: chmod +x telnet.pl.
> Finally, just type ./telnet.pl and it should say: Usage: telnet.pl host
> user passwd. Run it with appropriate parameters and it will connect
> everytime it is disconnected and will issue the idleCommand every
> idleTime period.
> 
> For those of you wondering why it took so long, it's because my native
> tounge is not perl (I try to avoid it like the plague :-). I needed to
> first find out why telnet -l username hostname didn't work as expected,
> it's supposed to login with your supplied username, but then it prompts
> for a password - not good. Then I figured that I could probably write a
> script, and seeing that it was unlikely that Scott had PHP installed, I
> figured that using perl would be simpler. Then went looking for
> something that allowed me to telnet using perl, then needed to figure
> out how to get command line parameters to the script, since I didn't
> really want Scott to have to change the script.

At first I was unable to get the Net::Telnet module to work. I was presented
with many different errors when trying to install the module in the command
prompt (segmentation error, Perl Library incomplete, package incomplete,
etc.) I didn¹t believe any of these to be true however. The package was
complete and I was quite sure that the OSX Perl Libraries would be too.

I managed to get the Net::Telnet module to install but had to be logged in
as root. I also found a file called "perl.h" that was not in the OSX Perl
Libraries in the latest release of Perl off a CPAN ftp server.

I placed the "perl.h" file in the System/Perl/Darwin/CORE folder. (all this
also has to be done logged in as root otherwise you get an error saying the
folder and files cannot be modified) I then tried to install the Net::Telnet
module again.

It works up to the part where you use the "make" command to create the man
file. I got an error saying "No such command" I ignored it and tried the
script as I didn¹t think the man file was essential.

I logged back in under my normal account.

I saved the above script (v1.0 - May 1, 2002 by Onno Benschop - Itmaze) in
XperlEdit v1.2 into the Home folder.

I then ran the script and it worked fine but did not display anything in the
Terminal window. (If this does not work make sure that the Telnet.pl file
you have saved does not contain any html or other characters)

The script keeps the telnet session open like it should. It has been running
now for a bit under 24 hours.

Regards,
Scott