Grep output to a webpage

Tater73
Tater73 used Ask the Experts™
on
I need to write a script/utility that will allow the user to input a hostname thru a web interface that will grep the /etc/hosts file and display the output to a webpage.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011
Commented:
<HTML>
<HEAD><TITLE>Enter hostname HTML tag</TITLE></HEAD>
<BODY bgcolor="#cccccc" text="#000000">
<H2>Test ISINDEX HTML tag</H2>
<ISINDEX prompt="Enter hosname:" action="http://localhost/cgi-bin/grep-hosts">
</BODY>
</HTML>

--- /path-to-"web site rot"/cgi-bin/grep-hosts ---
#!/bin/bash

grep $1 /etc/hosts
------------

chmod +x /path-to-"web site rot"/cgi-bin/grep-hosts
Julian ParkerSenior Systems Administrator

Commented:
you will probably need to add;

echo "Content-type: text/plain"
echo ""

after the #!/bin/bash so the browser knows how to deal with it or you may get a bad header.

I'm not suggesting you should use `isindex` most places suggest you use a form.

You should take care about validating inputs, it may be possible to enter some query that compromises the system, that said it does work.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial