?
Solved

Using shell script for CGI

Posted on 1998-12-04
9
Medium Priority
?
276 Views
Last Modified: 2013-12-25
I want to use a shell script as a cgi that basically GREPs
a text file.  I can use $QUERY_STRING in the grep statement,
but if I call this script from a form and pass it a value,
what's the easiest way of stripping the name= prefix from the value of QUERY_STRING?  I only need to pass one value.

Here's the basic script:

#!/bin/sh
echo Content-type: text/html
echo
echo '<HEAD><TITLE>Search</TITLE></HEAD>'
echo '<P>'
echo Searching on: $QUERY_STRING
echo '<P>'
echo '<H4><PRE>'
grep $QUERY_STRING /somedir/myfile.txt
echo '</PRE></H4>'

Calling the cgi as a standalone URL works, but with a FORM the name= is prepended to the query - how can I reference everything after the '=' in the GREP?
0
Comment
Question by:wisdom042597
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
9 Comments
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1829945
try:
grep "perl -F"name:" -ane 'print $F[1];" myfile.txt
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1829946
arg---
I mean:

perl -F"name:" -ane 'system("grep $F[1] myfile.txt")'

sorry.
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1829947
god, I am dumb today.
last try:

echo $QUERY_STRING | perl -F"name:" -ane 'system("grep $F[1] myfile.txt")'
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 1

Author Comment

by:wisdom042597
ID: 1829948
I'd prefer a shell-based solution, not using Perl.  I don't want to call Perl and allocate 500+k of memory for such a simple operation.
0
 
LVL 8

Accepted Solution

by:
MaDdUCK earned 150 total points
ID: 1829949
then experiment with
echo $QUERY_STRING | cut -f 2 -d: -s
which will return what you are looking for.
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1829950
echo "name:ma" | cut -f 2 -d= -s
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1829951
argh!
I am wild again.
I mean
echo $QUERY_STRING | cut -f 2 -d= -s

sorry sorry
0
 
LVL 1

Author Comment

by:wisdom042597
ID: 1829952
Thanks - this does work.  It would be nice if you explained more about how it works and how to customize it.  I modified my script to set another environment variable equal to the results of the operation so I could use the processed data in multiple statements.
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1829953
the best way to find out is to type 'man cut' in UNIX. cut is a utility which is intended to split strings into parts.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question