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.
-- 
()/)/)() ..ASCII for Onno.. 
|>>? ..EBCDIC for Onno.. 
--- -. -. --- ..Morse for Onno.. 

ITmaze - ABN: 56 178 057 063 - ph: 04 1219 8888 -  
[EMAIL PROTECTED]