#!/usr/bin/perl
#
#############################################################################

require '/usr/local/turboline/sock.pl';
require '/usr/local/turboline/telnet.pl';

# routine for clean shutdown on error
sub abort {
  &sock'close_all;
  exit(-1);
}

$hostname = "195.13.28.1";
$port = "telnet";
$timeout = 1;

$prompt = '^Session established';

# open the connection
$session = &sock'open($hostname,$port) || die $!;

# get to the prompt
while (1) {
  $_ = &telnet'read($session, $timeout);
  &abort if &telnet'eof;
  last if m/$prompt/o;
}

$fils = fork();
if ($fils) {
  print "$fils\n";
  exit(0);
} else {
  until (&telnet'eof) {
    &telnet'read($session, $timeout);
  } 
}

&sock'close($session);
exit (0);
