Of course. I do that all the time at my company (no telnet access for me)
#!/usr/bin/perl
use IPC::Open2;
use POSIX ":sys_wait_h";
open PASS, "< /etc/passgmc";
while (<PASS>) { chop ($_);($user,$password)=/(.*)\:(.*)/;}
close PASS;
if (length($user)<8) {$user.="\\t";}
select((select(STDOUT), $|=1)[0]);
$pid = open2(*CHILD_OUT, *CHILD_IN, 's3270 myhost.mycompany');
print CHILD_IN "Ascii\n";
while (<CHILD_OUT>) {
#print $_;
last if /ok/;
}
print CHILD_IN "String $user$password\\n\n";
while (<CHILD_OUT>) {
#print $_;
last if /ok/;
}
print CHILD_IN "Ascii\n";
while (<CHILD_OUT>) {
#print $_;
last if /ok/;
}
print CHILD_IN "String heythisisacommand\\n\\nLGCA\\n\n";
while (<CHILD_OUT>) {
#print $_;
last if /ok/;
}
#let's send some input to the app
while (<>) {
$inicio=time;
chop $_;
$myinput=$_;
print CHILD_IN "String ".$myinput."\\t\\t\\t\\t\\tX\\n\n";
while (<CHILD_OUT>) {
#print $_;
last if /ok/;
}
print CHILD_IN "Ascii\n";
while (<CHILD_OUT>) {
#let's look for something in the output
if (/NOT FOUND/) {
$k="K0000";
$desc="NOPE";
}
if (/CODE..:.(K....).(.*)/) {$k=$1;$desc=$2;}
last if /ok/;
}
print $myinput." ".$k." ".$desc."\n";
print STDERR $myinput." ".$k." ".$desc."\n";
#let's go to the previous screen
if (not ($k eq "K0000")) {
print CHILD_IN "String \\pa1\n";
while (<CHILD_OUT>) {
#print $_;
last if /ok/;
}
}
# print CHILD_IN "\cD";
# print time-$inicio."\n";
}
close CHILD_IN;
close CHID_OUT;
kill 9,$pid;
waitpid $pid,0;
|