4

Ok so I have a bash file that does various operations on a linux server.

I need to pass 7-8 variables to the bash file, and these variables will be set by a user on a simple webpage.

Just wondering if this is possible or do I need to script the bash file call through some other language?

Looking into calling functions on a bash file from http://www.tldp.org/LDP/abs/html/functions.html is this the right lines?

can't seem to find a good resource to guide me on this so any links or examples appreciated

Fuzzybear
  • 1,388
  • 2
  • 25
  • 42

2 Answers2

8

If you're running PHP on the web server, then you can post your web form to a PHP script, then use PHP's shell_exec() function to call your bash script and pass the inputs. As paulsm4 mentions above, any time you call a shell script and pass inputs to a shell script from the web, you need to be very careful to sanitize the inputs to prevent injection type of attacks. One way to do this is to do all the validation and sanitization in the PHP script, before calling the shell script by way of shell_exec() to ensure that you are passing only clean input to the shell script.

See http://php.net/manual/en/function.shell-exec.php

mti2935
  • 11,465
  • 3
  • 29
  • 33
  • 2
    +1 for the PHP approach. Note that the sanitizatzion is done best using [`escapeshellarg()`](http://www.php.net/manual/en/function.escapeshellarg.php) – hek2mgl Jul 21 '13 at 13:28
  • This is truly awesome the webpage was going to be a php page anyway so this will save me a lot of time, and yes all the sanitation of the inputs will be done on the php page. Many thanks everyone love this community :) – Fuzzybear Jul 21 '13 at 14:17
4

Yes, you can. You want "CGI" (Common Gateway Interface). It's a huge potential security risk: be careful!

Just Google for CGI bash. For example:

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190