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

How do I get input from a form to run a linux shell script?

I have a script on a linux box that runs as this "script.sh argument1 argument2" How would I be able to define the arguments by a simple HTML form so that someone could run the report that this generates?
1 Solution
Create a form, eg:

<form action="/cgi-bin/script.pl" method="POST">
<i<input type="text" name="arg1" size="20">
<input type="text" name="arg2" size="20">

Then script.pl looks like:

use CGI;
my $q = new CGI;
my $arg1 = $q->param('arg1');
my $arg2 = $q->param('arg2');
print $q->header('text/plain');
system "/path/to/script.sh", $arg1, $arg2;

Note that you should make sure you sanitise any data from the form before calling the script.
guitchickenAuthor Commented:
Thanks, that worked great! I had the script already made but was asked for a web form to run it last minute and this definately saved me time trying to find out what needed to be done.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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