in reply to Re: Re: Net::Telnet + Term::VT102 sample
in thread Net::Telnet + Term::VT102 sample

Here is the script, just in case some good soul is wishing to help me:
#!/usr/local/bin/perl
use Net::Telnet qw(TELOPT_TTYPE);
use Term::VT102;




#####
$username="xxx";
$passwd="xxx";
$server="10.52.36.17";
$logfile="script.log";
######

    $t = new Net::Telnet (Timeout => 10);
    $t->open($server);
    $fh = $t->dump_log($logfile);
    $t->login($username, $passwd) or die "Cannot login";
    $t->option_callback (\&opt_callback);
    $t->option_accept ('Do' => TELOPT_TTYPE);
    $t->suboption_callback (\&subopt_callback);
$cmd="su -";
$cmd2="rootpassword";

# here I su to root user
$su=$t->cmd( String => $cmd,
Prompt  => '/root/');
print $su;

# send root password
$pw = $t->cmd($cmd2);
print $pw;

#set TERM
$cmd="export TERM=ansi";
esegui();

#flush buffer
$|=1;

my $vt = Term::VT102->new (
  'cols' => 80,
  'rows' => 25,
);

#
$vt->callback_set ('OUTPUT', \&vt_output, $t);
$command="cicsterm -Q -A -T=OPT1*9700702*0005984044*0000000*01\n";
$vt->resize(80,25);
$vt->process ($command);

	print "\eH";	# return to the top left of the (real) screen
	for (my $row = 1; $row <= $vt->rows (); $row++) {
		printf "%s\n", $vt->row_plaintext ($row);
	}
	printf "Cursor position: (%d, %d)",
	  $vt->x (),
	  $vt->y ();

$vt->process ($command);

	for (my $row = 1; $row <= $vt->rows (); $row++) {
		printf "%s\n", $vt->row_plaintext ($row);
	}


$t->close;


print "\n**************end script************\n";
close $fh;
exit;


sub esegui {
@lines = $t->cmd( String => $cmd,
Prompt  => '/\@svuni046\/>/'); 
print @lines;	
	}


#
sub opt_callback {
	my ($obj,$opt,$is_remote,$is_enabled,$was_enabled,$buf_position) = @_;

	if ($opt == TELOPT_TTYPE and $is_enabled and !$is_remote) {
		#
		# Perhaps do something if we get TELOPT_TTYPE switched on?
		#
	}

	return 1;
}


# Callback for sub-option handling - for Net::Telnet.
#
sub subopt_callback {
	my ($obj, $opt, $parameters) = @_;
	my ($ors_old, $otm_old);

	# Respond to TELOPT_TTYPE with "I'm a VT102".
	#
	if ($opt == TELOPT_TTYPE) {
		$ors_old = $obj->output_record_separator ('');
		$otm_old = $obj->telnetmode (0);
		$obj->print (
		  "\xff\xfa",
		  pack ('CC', $opt, 0),
		  'vt102',
		  "\xff\xf0"
		);
		$obj->telnetmode ($otm_old);
		$obj->output_record_separator ($ors_old);
	}

	return 1;
}


# Callback for OUTPUT events - for Term::VT102.
#
sub vt_output {
	my ($vtobject, $type, $arg1, $arg2, $private) = @_;

	if ($type eq 'OUTPUT') {
		$private->print ($arg1);
	}
}

  • Comment on Re: Re: Re: Net::Telnet + Term::VT102 sample