Sending F3 to ksh using Net::Telnet

I've written a script to telnet to a box and run a grep command and save it into a list, but our server is a unix box and requires you to press F3 before it gives you the shell prompt. I can't figure out how to give it an F3 from perl. Any help would be appreciated. Here's the code.

#!perl


use strict;
use warnings;
use diagnostics;

use lib '/server/share/';
use Net::Telnet ();

my $login = "name";
my $pass = "pass";
my $ttyType = "vt100";
my $profs_id = "username";

#Begin Telnet

print "Wrong number of arguments" and die "$!\n" unless @ARGV > 0;

my $input = shift;
my $isp = "server.s0".$input;

my $t = new Net::Telnet (Timeout => 50,
                 Prompt => '/\$ $/');
                                     
                                    
$t->open($server);

$t->waitfor('/login: $/i') or die $t->lastline;
$t->print($login);
print $t->lastline;

$t->waitfor('/Password: $/i') or die $t->lastline;
$t->print($pass);
print $t->lastline;

$t->waitfor('/TERM= /i') or die $t->lastline;
$t->print($ttyType);
print $t->lastline;

$t->waitfor('/profs*/') or die $t->lastline;
$t->print($profs_id);
print $t->lastline;

$t->waitfor('/SECADMIN/') or die $t->lastline;
$t->print("^[OR");  #problem is here with the disclaimer  you press F3 to get to the prompt
print $t->lastline;

my @output = $t->cmd("setaddr -l | grep 008064");
print $t->lastline;
print @output;
LVL 1
TristinColbyAsked:
Who is Participating?
 
TintinConnect With a Mentor Commented:
Firstly, you need to find what sequence F3 gives you.

From your command line, type

cat -v

then press F3.

It should output something like

^[[13~

which means the sequence F3 sends is

Esc [13~

Which translates to sending

"\e[13~"

0
 
ozoConnect With a Mentor Commented:
you might try sending  "\eOR"
0
 
TristinColbyAuthor Commented:
I've tried that.  It doesn't work.  its a ksh, but I don't know if the ksh starts before or after i press f3.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
ozoCommented:
Does it work when you telnet manually?
0
 
TristinColbyAuthor Commented:
Tintin,
Its a little weird though. When I press F3 it prints an R then when I press enter it prints ^[OR


I tried sending \e^[OR but it didn't work.  $t->print("\e^[OR");  Here's a list of things I've tried so far.

$t->print("^[OR");
$t->print("\eOR");
$t->print("\e^[OR");
$t->print( "^\[OR";)  
0
 
TristinColbyAuthor Commented:
It does work when I telnet manually.
0
 
ozoCommented:
what do you get when you press F3 in
od -c
can you try a $t-put inseas of $t->print?
0
 
TristinColbyAuthor Commented:
Okay , I've figured this much out.  The disclaimer is being displayed by the shell script /u/bin/notices

From the file:
Notices will display any file in the $DD_SYLIB/notices directory.
The notices are displayed as the user logs in before the menu screen.
The find command will delete all files older than 3 days.

end if paste

But what i can't figure out is what triggers the f3 key to let the screen go. here's the script. in its entirety

#!/bin/sh
#@(#)notices    1.2  06/13/90 17:14:12
##
##
##
## Notices will display any file in the $DD_SYLIB/notices directory.
## The notices are displayed as the user logs in before the menu screen.
## The find command will delete all files older than 3 days.
##
##
##

trap "rm -f /tmp/all$$ /tmp/not.$$" 2 9 12

find $DD_SYLIB/notices -type f -mtime +3 -print >/tmp/not.$$

for file in `cat /tmp/not.$$`
do
   if [ -f $file ]
   then
      /bin/rm -f $file
   fi
done


cat $DD_SYLIB/notices/* > /tmp/all$$ 2> /dev/null

if [ $? = 0 ]
then
   viewfile -t"Display Notices" -l2000 /tmp/all$$
fi

rm -f /tmp/all$$ /tmp/not.$$
0
 
TristinColbyAuthor Commented:
I can also do a ctrl-c to get past it but when I send \cc through the script I get the following error:

Uncaught exception from user code:
        pattern match read eof at C:\Documents and Settings\user\Desktop\Fetc
h_All_TC.pl line 58
        Net::Telnet::_croak('Net::Telnet=GLOB(0x1c4dd2c)','pattern match read eo
f') called at C:/Perl/site/lib/Net/Telnet.pm line 539
        Net::Telnet::error('Net::Telnet=GLOB(0x1c4dd2c)','pattern match read eof
') called at C:/Perl/site/lib/Net/Telnet.pm line 362
        Net::Telnet::cmd('Net::Telnet=GLOB(0x1c4dd2c)','setaddr -l | grep 008064
') called at C:\Documents and Settings\user\Desktop\Fetch_All_TC.pl line 58
0
 
ozoCommented:
Could you try removing the viewfile -t"Display Notices" -l2000 /tmp/all$$
from the script?
0
 
TristinColbyAuthor Commented:
Oooh no, I can't do any editing on this file.
0
 
TristinColbyAuthor Commented:
Viewfile is the actual application that is asking for f3.
0
 
ozoCommented:
Do you know what the -l2000 means?
0
 
TristinColbyAuthor Commented:
lines
0
 
ozoCommented:
What are the symptoms you are seeing?
Can you get an Input_log and Output_log and compare it t what you see when you telnet manually?

Did you try $t-put with a pause before and after?
0
 
TristinColbyAuthor Commented:
yeah, nothing i send bypasses the screen.
0
 
ozoCommented:
What are the symptoms you are getting?  do you die $t->lastline;?
does print @output; print the wrong thing?
How does it compare with what happens manually?
When you telnet manually, can you type F3 before viewfile finishes printing?
0
 
TristinColbyAuthor Commented:
No it doesn't die, it just times out. I've tried a timeout of 100 which is forever. when you hit f3 its almost instantanious.  The file is only the size of a normal dos window.  Its got something to do with the keys i'm sending, but viewfile may interpret f3 different.  
0
 
ozoCommented:
what times out?  the $t->waitfor('/SECADMIN/')?
Can you print the log of what was sent back?

Can you hit f3 before viewfile starts?
0
 
TristinColbyAuthor Commented:
The timeout issue is fixed.  I mistyped the regex.  no you can't hit f3 before viewfile starts. Its instantanious.  It still won't take the the keys.  You can't do anything until you get past the viewfile application.  No commands.  So the entire script is worthless unless I can get past the viewfile.  Anyone else have any ideas?
0
 
Adam314Commented:
Do you have a telnet program that can record the exact bytes sent?  If so, use that to log in, press F3, and look at what bytes are sent.

Do you have access to the viewfile program?  Is it a script?  Compiled?  Do  you have the source code?
0
 
TristinColbyAuthor Commented:
alright, I found out how to bypass it all together. Just enter exit as the termtype and it crashes out the login script so that viewfile doesn't even get executed. ha ha. The only problem is now that i'm not getting any output in my list.  It shows up in my input_log.log just not on the screen, which is what I want. Here's the current script.

use strict;
use warnings;
use diagnostics;

use lib '//server/perl/net/';
use Net::Telnet ();

my $login = "name";
my $pass = "pass";
my $ttyType = "exit";  #Set Term Type to exit to bypass notices
my $profs_id = "creds";

#Begin Telnet

print "Wrong number of arguments" and die "$!\n" unless @ARGV > 0;

my $input = shift;
my $isp = "isp.s0".$input;

my $t = new Net::Telnet (Timeout => 15,
                                     #Prompt => '/\$ $/',
                                     Dump_Log => "Dump_Log.log",
                                     Input_Log => "Input_Log.log");

$t->open($isp);

$t->waitfor('/login: $/i') or die $t->lastline;
$t->print($login);

$t->waitfor('/Password: $/i') or die $t->lastline;
$t->print($pass);

print "Logged in.\n";

$t->waitfor('/TERM=/i') or die $t->lastline;  #Set Term Type to exit to bypass notices
$t->print($ttyType);
print "Term Type Set\n";

$t->waitfor('/profs*/') or die $t->lastline;  #Enter profs id
$t->print($profs_id);
print "profs ID set\n";

print "Getting Thin Client List\n";
#$t->waitfor('m/\/is\/$ $/i');
$t->waitfor('/[\$%#>] $/');

my @output = $t->print("setaddr -l | grep 008064");

$t->waitfor('/[\$%#>] $/');

print @output;   #Right here prints a 1.  Not the actual output.
0
 
TristinColbyAuthor Commented:
alright guys, its solved.  the issue is with the last 3 lines.  Thanks to everyone who helped.

it SHOULD read

$t->print("setaddr -l | grep 008064");

my @output = $t->waitfor('/[\$%#>] $/');

print @output;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.