I have created this CGI perl script which calls a shell script (lookup.sh) to query an Oracle database using the first arg passed to the shell script as the user name to cross reference against group membership.
The shell script returns all of the groups delimited by new lines. I have this Perl script as the CGI action to a very simple html form which passes the USER parameter to the perl script, then the perl script runs the shell script and passes the username from the original html form as the first arg and should then store the returned values in an array called @outp
.
My testing shows everything to be working but when I run it from a browser the @outp
array comes out blank every time. All other tests have the array containing the correct data, the only assumption I can make is that the HTML is generated before the array is populated with data from the backticks command. Can someone chime in?
HTML:
<FORM action="/cgi-bin/test.cgi" method="POST">
USER: <input type="text" name="USER"> <br>
<input type="submit" value="Submit">
</FORM>
Shell:
#!/bin/bash
sqlplus -s DB_USER/DB_PASS@//DB_HOST:1521/JIRA_RW <<< "SELECT GROUP_NAME from jira_db.membershipbase where USER_NAME='$1';"
Perl:
#!/usr/bin/perl
use CGI qw(:standard);
$data = param('USER') || '<i>(No input)</i>';
@outp = `/bin/lookup.sh $data`;
print <<END;
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<title>Jira User Query</title>
<h1>Group Membership for $data @outp</h1>
<p>print @outp</p>
END
and yes, I know this is a TOTAL hack job.