LinuxQuestions.org
Have you listened to LQ Radio?
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Tags used in this thread
Popular LQ Tags , , , ,

Reply
 
Thread Tools
Old 11-05-2009, 10:11 AM   #1
doomed9
LQ Newbie
 
Registered: Nov 2009
Location: bahama, nc
Distribution: freebsd, ubuntu, gentoo
Posts: 3
Thanked: 0
Question how do i use s3270/x3270 for scripting


[Log in to get rid of this advertisement]
I'm trying to write a script which will (upon completion), navigate through records maintained on an IBM mainframe using a tn3270 terminal, and scrape said records into html files for later manipulation.

I've read http://x3270.bgp.nu/s3270-man.html

and http://x3270.bgp.nu/x3270-script.html

The latter states:
Quote:
Commands are emulator actions; the syntax is the same as for the right-hand side of an Xt translation table entry (an x3270 or c3270 keymap). Unlike translation tables, action names are case-insensitive, can be uniquely abbreviated, and the parentheses may be omitted if there are no parameters. Any input line that begins with # or ! is treaded as a comment and will be ignored.
So...

By that definition, the following should work:

Code:
connect(L:ssl3270.myhost.org:2023) \
ascii() \
string(command1) \
enter() \
ascii() \
enter() \
string(command2) \
ascii() \
pf(3) \
quit()

However, when i call the above using the script() function in s3270, the script prints to stdout, but the actions are not executed as expected.

For example:

Code:
(NOTICE: I've shortened the script for example's sake)
$ s3270
script(/path/to/my/script/test.3270)
connect(L:ssl3270.myhost.org:2023)
ascii()
string(command1)
enter()
ascii()

L U U N N 4 24 80 0 0 0x0 -
ok
Expected output would've been (for starters) the first character of the status string changing to U (as the keyboard should unlock when i am connected), and the initial screen printed in ascii, a command sent, and the resulting screen printed in ascii as well.

I'm not sure what i am doing wrong. Can someone give me an example script that works? Something simple that depicts how i can use something like bash, perl, or python to send commands to this application and navigate through screens.

Thanks in advance

Last edited by doomed9; 11-05-2009 at 10:14 AM.. Reason: pointing out that the script i executed has been shortened from the example i gave earier in the post
windows_vista doomed9 is offline  
Tag This Post , , , ,
Reply With Quote
Old 11-05-2009, 08:12 PM   #2
doomed9
LQ Newbie
 
Registered: Nov 2009
Location: bahama, nc
Distribution: freebsd, ubuntu, gentoo
Posts: 3
Thanked: 0

Original Poster
bash

So, i worked out how to do this in bash; though, i don't like the result.

Code:
#!/bin/bash
file_path="/path/to/my/files"
date=$(date +"%Y%m%d%H%M%S")
x3270if "connect(L:ssl3270.myhost.org:2023)"
x3270if "printtext(html,file,$file_path/myhost-$date.html)"
x3270if "string(command1)"
x3270if "enter"
x3270if "printtext(html,file,$file_path/myhost-$date.html)"
x3270if "enter"
x3270if "string(command2)"
x3270if "enter"
This is a bash script that, if called from within s3270, will navigate to the application login page and create html files of each page along the way.

while x3270if is nice, i reckon i expected a simpler solution...something easier to use with a language's built-in functionality.

What would i do with perl? Hopefully not make a call to system() each time i want to input data. Is there a way to treat the terminal connection as a file handle and just send commands to it via print()?
windows_vista doomed9 is offline     Reply With Quote
Old 11-06-2009, 02:18 AM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 5.4
Posts: 7,429
Thanked: 326
If you're keen on doing this in Perl, ask the gurus over at http://www.perlmonks.org/
windows_xp_2003 chrism01 is offline     Reply With Quote
Thanked by:
Old 11-07-2009, 05:55 PM   #4
doomed9
LQ Newbie
 
Registered: Nov 2009
Location: bahama, nc
Distribution: freebsd, ubuntu, gentoo
Posts: 3
Thanked: 0

Original Poster
Thumbs up Thanks

Chris,

Thank you for the excellent referral. I was on the right track to my answer in a few minutes...

Using perl's IPC::Run module, i was able to pipe commands directly to the s3270 subprocess. Thus, the below is an example of x3270's peer script facility:

Code:
#!/usr/bin/perl

my @s3270 = s3270;

use IPC::Run qw( start pump finish timeout );
$IPCRUNDEBUG=details;
      # Incrementally read from / write to scalars.
      # $in is drained as it is fed to s3270's stdin,
      # $out accumulates s3270's stdout
      # $err accumulates s3270's stderr
      # $h is for "harness".
      my $h = start \@s3270, \$in, \$out, \$err, timeout( 10 );

      $in .= "connect(L:ssl3270.myhost.org:2023)\n";
      $in .= "ascii\n";

      $in .= "quit";
      finish $h or die "s3270 returned $?";

      warn $err if $err;
      print $out;         ## All of cat's output
hope this helps any googlers interested in scripting with s3270.

Chris, Thanks again
windows_vista doomed9 is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
x3270/s3270 Scripting [IBM Mainframes] arkanunz Linux - Software 3 12-04-2008 09:18 PM
what is this x3270??? muzzamil.luqman Linux - Newbie 7 12-03-2008 07:52 PM
x3270 emulator bourne Linux - Software 9 11-03-2008 12:42 PM
x3270 Install issue jlueke Linux - Software 0 11-21-2005 04:33 PM
x3270 nex6 Linux - Software 1 03-03-2005 01:48 PM


All times are GMT -5. The time now is 05:49 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration