• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

Using shell script for CGI

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
wisdom042597
Asked:
wisdom042597
  • 7
  • 2
1 Solution
 
MaDdUCKCommented:
try:
grep "perl -F"name:" -ane 'print $F[1];" myfile.txt
0
 
MaDdUCKCommented:
arg---
I mean:

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

sorry.
0
 
MaDdUCKCommented:
god, I am dumb today.
last try:

echo $QUERY_STRING | perl -F"name:" -ane 'system("grep $F[1] myfile.txt")'
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
wisdom042597Author Commented:
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
 
MaDdUCKCommented:
then experiment with
echo $QUERY_STRING | cut -f 2 -d: -s
which will return what you are looking for.
0
 
MaDdUCKCommented:
echo "name:ma" | cut -f 2 -d= -s
0
 
MaDdUCKCommented:
argh!
I am wild again.
I mean
echo $QUERY_STRING | cut -f 2 -d= -s

sorry sorry
0
 
wisdom042597Author Commented:
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
 
MaDdUCKCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now