Download - Perl 1997 Perl As A System Glue
Perl As A System Glue
Patrick M. BensonUniversity of Washington
Information Systems
http://weber.u.washington.edu/~pbensonemail: [email protected]
2
Overview of Examples
File Store-and-ForwardIntroductory Level Example
Perl CGIIntermediate Level ExampleHalf-a-Perl ConceptSQL Development
3
File Store-and-Forward
VAX/VMS with Multinet outside our firewall running FOCUS under DCL
RS-6000 UNIX/AIX inside our firewall with strict security measures
IBM-309x/VM with an unknown Comm System on dedicated RJE line through our firewall
4
File Store-and-Forward
firew
all
firew
all
firew
all
firew
all
.rhost/.netrc .netrc/unknown
file to forward'datafile'
Returned Copyof file
'datafile_check'
DestinationCopy of'datafile'
Return Copy of'datafile'
Send Copy of'datafile'
Local Net VAX/VMS RS-6000/AIX IBM 309x/VMUsers
Xterm, PC, Mac
Create and IssueRSH comands for
FTP process
Display DestinationDirectory, run DIFF
on datafile anddatafile_check
Issue Directory,Get, Put FTP
commands; thenremove datafile(s)
Issue Get.Directory, Delete,
Put FTP commands
Respond to Dir, Put,Get FTP commands
5
File Store-and-Forward
RSH and FTP work because ... I trust you enough to let you talk to me,
I’ll take data files you say are safe. You trust me enough to give me your
account / password and to let me send a copy of your data file back to you.
6
Perl in this process (See Listing 2, RS6000/AIX Perl Script)
IF Statements, Logical Operators, Code Blocks
16. if ($#ARGV != 1) {
17. print “\n\n *******************************************”;
18. print “\n * ARGUMENT MISMATCH ERROR #”, $#ARGV *”;
19. print “\n *******************************************\n”;
20. exit -1;}
Arguments, Array Notation, Concatenation, Constants
23. $infile = $ARGV[0];
24. $chkfile = $infile . ‘_check’;
Back-Tic Execution, Nested Quotes, Imbedded Pipes
43. $get_file = ‘echo “get $outfile $chkfile” | ftp vsvm.dis.wa.gov‘;
File Store-and-Forward
7
Overview of Examples
File Store-and-ForwardIntroductory Level Example
Perl CGIIntermediate Level ExampleHalf-a-Perl ConceptSQL Development
8
Perl CGI
Web Client (PC, Mac, Xterm with Netscape 2.1 or better or similar, marginal HTML 3.0 or better compliant)
Web Server (Perl 4.2 or better) Data Server (Unix Box with Informix,
Sybase, Oracle ISQL or similar)
9
Perl CGI
Hypertext Transfer Protocol(HTTP)
Web Client(Netscape 3.0+ or
similar, HTML 3.0+)
Hard Firewall
HTML and PerlLibrary
WEB SERVER
S
oft
Fire
wal
l
Perl Scripts(Dynamic
HTML)
Static HTMLDEVELOPMENT
SERVERPico, VI, etc.text editors
Static DataServer 'Half-a-Perl' files
RSHCommand
Files
SQL Engine
Soft
Fire
wal
l
Web Side "Half-a-Perl"
Web-Side'Half-a-Perl'
Data ServerResponse
Web Side 'Half-a-Perl'
DS Side 'Half-a-Perl'
Target SQLDatabase
TemporaryDisk Files
UNLOAD Data
UNLOAD Data
Data Server 'Half-a-Perl' Scripts
Hard Firewall
DATA SERVER
SELECT Data
Common GatewayInterface (CGI)
10
Perl CGI
Content, Cache Control, Libraries, Initialization Accept static HTML parameters & Main Driver Construct ISQL command to meet request Copy the ISQL command through the firewall
to a data file Pass filename and CAT statements as a
parameter to ISQL command file Parse returned string into rows Build HTML Page
11
Perl CGI
See Listing 3, Perl CGI Content, Cache Control, Libraries, Initialization
9. print "CONTENT-TYPE: text/html","\n";10. print "Pragma: no-cache","\n\n";12. require "/www/world/cgi-bin/cgi-lib.pl";14. $rcp_user = ‘oasis’;15. $rcp_cmd = ‘/usr/ucb/rcp’;16. $rcp_host = ‘equip.u.washington.edu’;18. $rsh_user = ‘oasis’;19. $rsh_cmd = ‘/usr/ucb/rsh’;21. $sql_host = ‘equip.u.washington.edu’;22. $sql_db = ‘oasisdev@equipdev’;27. $rcp_destination = $rcp_user . ‘\@’ . $rcp_host . ‘:.’;28. $sql_user = $sql_host . ‘ -l ‘ . $rsh_user . ‘ ‘;
12
Perl CGI
See Listing 3, Perl CGI Accept static HTML parameters & Main
Driver
37. &ReadParse;
39. $table_name = $in{'table_name'};
41. $set_extract;42. &run_extract;43. &write_report;
45. exit;
13
Perl CGI
See Listing 3, Perl CGIConstruct ISQL command to meet request
49. sub set_extract {
53. $sellist = ‘name_value, name_full_text’;
54. $passlist = “'$table_name'”;
55. $sql_tables = ‘UNLOAD TO TEMPTBL SELECT ‘ . $sellist
56. . ‘ FROM names’
57. . ‘ WHERE name_type = ‘ . $passlist
58. . ‘\n’;
59. }
14
Perl CGI
See Listing 3, Perl CGICopy the ISQL command through the firewall to a data file
76. $info_time = `$rsh_cmd $sql_user "/bin/date "`;
77. if ($info_time eq '') {
78. print "<P>Database Server not responding ... try again later.";
79. exit;
80. }
85. $d = `rcp isql_tables.sql $rcp_destination`;
15
Perl CGI
See Listing 3, Perl CGI Pass filename and CAT statements as a
parameter to ISQL command file
94. $info = `rsh $sql_user "$rsh_file $sql_db isql_tables.sql; cat -e -v TEMPTBL ; rm TEMPTBL"`;
16
Perl CGI
See Listing 3, Perl CGI Parse Returned String into Rows
100. @table_data = split('\|\$',$info);
101. $row_count = $#table_data;
102. @row_data = split('\|',$table_data[0]);
103. $col_count = $#row_data + 1;
17
Perl CGI
See Listing 3, Perl CGIBuild HTML Page
108. sub write_report {
110 &build_headers;
111. &write_header;
112. &write_body
113 &write_footers;
114. }
18
Perl CGI
See Listing 3, Perl CGIBuild HTML Page - Build Headers122. $table_title[0] = ‘Column 1’;
123. $table_title[1] = ‘Column 2’;
125. if ($table_name eq “class”) {
126. $table_title[0] = ‘Class Code’;
127. $table_title[1] = ‘Class of Equipment’;
128. elsif ($table_name eq "cond") {
129. $table_title[0] = ‘Condition Code’;
130. $table_title[1] = ‘Asset's Present Condition’;}
(and so on until all possible table column titles are set)
140. }
19
Perl CGI
See Listing 3, Perl CGIBuild HTML Page - Write Header144. sub write_header {
148. print <<end_of_header;
149. <HTML>
150. <HEAD><TITLE>
151. Table Contents Inquiry
152. </TITLE></HEAD>
153. <BODY
161. end_of_header
162. }
20
Perl CGI
See Listing 3, Perl CGIBuild HTML Page - Write Body - Table Header175. print "<P> <TABLE COL=$col_count BORDER=\"1\" ";
176. for ($i = 0; $i < $row_count; $i++) {
180. if ($i == 0) {
181. print "<THEAD><TR>";
182. for ($j = 0; $j < $col_count; $j++) {
183. print "<TD ALIGN=\"CENTER\"> $table_title[$j] </TD>";
184. }
185. print "</THEAD><TBODY>";
186. }
21
Perl CGI
See Listing 3, Perl CGI Build HTML Page - Write Body - Table Rows195. @row_data = split('\|',$table_data[$i]);
196. for ($j = 0; $j < $col_count; $j++) {
197. if ($j == 0) {
198. $row_data[0] =~ s/\xA//g;
199. print "<TR><TD><FORMMETHOD=\"GET\"ACTION=\"./update_table.cgi\">
200. <INPUT TYPE=\"hidden\" NAME=\"$table_name\"
201. VALUE=\"$row_data[0]\">
202. <INPUT TYPE=\"SUBMIT\" VALUE=\"$row_data[0]\"></FORM></TD>";
203. } else {
204. print "<TD> $row_data[$j] </TD>";
205. }
206. }
22
Perl CGI
Hypertext Transfer Protocol(HTTP)
Web Client(Netscape 3.0+ or
similar, HTML3.0+)
OASIS HTML, Perl and Utilities
Library
Web Server
Sof
t
Fire
wal
lUtilities ("C"
and Perl)
Perl Scripts(Dynamic
HTML)
StaticFASTRANS
HTML
Pico, VI, etc texteditors
BrowserPrinted Output
Sof
t
F
irew
all
Time Request
CGI GeneratedSQL Cmd FIles
CAT'd SQLUNLOAD Files
Timestamp
Execute the Web"Half a Perl" Cmd
Hard Firewall
FASData Tables
PASData Tables
SQL Engine
SQL Engine
Hard Firewall
RSHCommand
Files
Data ServerTemp Disk
Storage
OASISData Tables
SQL Engine(Informix)
OASIS Data Server
Web Side "Half-a-Perl"
SQL UNLOAD'edData
CGI Generated SQLCommad FIles
FAS Data Server
PAS Data Server
Web Side "Half-a-Perl" for FAS Data
Web Side "Half-a-Perl" for PAS Data
FAS DataServer
Temp DiskStorage
PAS DataServer
Temp DiskStorage
Static DataServer "Half-
a-Perl"
Data Server Side"Half-a-Perl"
23
Perl As A System Glue
Pluses Cost effective cross platform superglue. Efficient and Structured code possible 1 hour of Perl = 8 hours of COBOLMinuses 10 ways to mess up maintenance staff Difficult post-implementation support
environment All the HTML Bandwagon problems